Skip to content

Does not reopen a new file during async writing #160

@zaverden

Description

@zaverden

According to the docs I can pass a new file path for reopen to continue to write into new file.

However, if I call reopen during async write it ignores new file path (https://github.com/pinojs/sonic-boom/blob/v3.2.0/index.js#L304-L308)

Code to reproduce

import { once } from "node:events";
import SonicBoom from "sonic-boom";

const startingPath = "1.log";
const newPath = "2.log";

const boom = new SonicBoom({ dest: startingPath, sync: false, append: true });

await once(boom, "ready");
console.log("file:", boom.file); // 1.log

boom.write("expect f1\n");

boom.once("write", () => {
  console.log("_writing:", boom._writing); // true
  boom.reopen(newPath);
});

await once(boom, "ready"); // emitted on reopen
console.log("file:", boom.file); //! 1.log, expected 2.log

boom.write("expect f2\n"); //! written into 1.log, expected into 2.log

workaround

- boom.reopen(newPath);
+ boom.file = newPath; 
+ boom.reopen(); 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions