Skip to content

Zlib and writeStream #51187

Open
Open
@kamatil-dev

Description

@kamatil-dev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    zlibIssues and PRs related to the zlib subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions