Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zlib and writeStream #51187

Open
kamatil-dev opened this issue Dec 16, 2023 · 1 comment
Open

Zlib and writeStream #51187

kamatil-dev opened this issue Dec 16, 2023 · 1 comment

Comments

@kamatil-dev
Copy link

kamatil-dev commented Dec 16, 2023

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
Copy link
Author

is there any further helping infos i can provide?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant