node icon indicating copy to clipboard operation
node copied to clipboard

Zlib and writeStream

Open kamatil-dev opened this issue 5 months ago • 1 comments

Version

21.4.0

Platform

Linux penguin 6.1.55-06877-gc83437f2949f #1 SMP PREEMPT_DYNAMIC Sat Dec 2 18:30:09 PST 2023 x86_64 GNU/Linux

Subsystem

Debian 11 (chromeos flex)

What steps will reproduce the bug?

import {
  open,
  rename,
} from "node:fs/promises";
import {
  createDeflate,
  createInflate,
  constants
} from "node:zlib";

const fileHandle = await open(filePath, "r"),
      writeStream = createDeflate({
        flush: constants.Z_FULL_FLUSH,
      }),
      fileTempHandle = await open(fileTempPath, "w");

writeStream.pipe(fileTempHandle.createWriteStream());

// using readline to read compressed file
createInterface({
    input: fileHandle
      .createReadStream()
      .pipe(createInflate()),
    crlfDelay: Infinity,
  })

write each line to the compressed file using writeStream.write(....); inside a for await loop

and then add some new lines and then run :

    writeStream.close(async () => {
      await fileHandle.close();
      await fileTempHandle.close();
      console.log("END", filePath);
      await rename(fileTempPath, filePath);
    });

ps: when not using flush: constants.Z_FULL_FLUSH i get an empty file with just the Gzip header (i guess)

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior? Why is that the expected behavior?

No response

What do you see instead?

Error: unexpected end of file
    at genericNodeError (node:internal/errors:956:15)
    at wrappedFn (node:internal/errors:510:14)
    at Zlib.zlibOnError [as onerror] (node:zlib:189:17) {
  errno: -5,
  code: 'Z_BUF_ERROR'
}

Additional information

No response

kamatil-dev avatar Dec 16 '23 20:12 kamatil-dev

is there any further helping infos i can provide?

kamatil-dev avatar Dec 17 '23 15:12 kamatil-dev