Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
Create archive from readable, add file and pipe to writable

The goal is to receive an archive form the client, add a file, and upload it to Cloud Storage without creating a temporary file. The client and the server both use the archiver library. The problem with the code below is that file2.txt does not get added to the archive.

Client:

import archiver from "archiver";

const archive = archiver("zip", {
    zlib: { level: 9 },
});

archive.append("string cheese!", { name: "file1.txt" });

await fetch(`/archive`, {
    method: "POST",
    body: archive,
});

Server:

import archiver from "archiver";
import { Storage } from "@google-cloud/storage";
import { Router } from "express";

const router = Router();
const storage = new Storage();

router.post("/", (req, res) => {
  const archive = archiver("zip", {
    zlib: { level: 9 },
  });

  const cloudFile = storage.bucket("archives").file("archive.zip");

  req.pipe(archive, {
    end: false,
  });

  archive.pipe(cloudFile.createWriteStream());

  req.on("end", async () => {
    archive.append("string cheese!", { name: "file2.txt" });
    archive.finalize();
    archive.end();
  });
});
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!