Compare commits

...

5 Commits

Author SHA1 Message Date
Jarred Sumner
8cbf373c31 Update fs.js 2023-06-25 16:04:09 -07:00
Hanaasagi
3a8cb27abd wait first stream finished 2023-06-26 00:44:20 +09:00
Hanaasagi
a2dcd680de fix lint 2023-06-26 00:16:36 +09:00
Hanaasagi
06f03d34da test append mode in createWriteStream 2023-06-25 22:30:48 +09:00
Hanaasagi
b33cdf586a Fix the parameters of the WriteStream constructor.
Close: https://github.com/oven-sh/bun/issues/3395
2023-06-25 22:25:58 +09:00
3 changed files with 42 additions and 4 deletions

View File

@@ -642,8 +642,8 @@ WriteStream = (function (InternalWriteStream) {
});
return Object.defineProperty(
function WriteStream(options) {
return new InternalWriteStream(options);
function WriteStream(path, options) {
return new InternalWriteStream(path, options);
},
Symbol.hasInstance,
{

View File

@@ -366,8 +366,8 @@ WriteStream = function(InternalWriteStream) {
return WriteStreamClass = InternalWriteStream, Object.defineProperty(WriteStreamClass.prototype, Symbol.toStringTag, {
value: "WritesStream",
enumerable: !1
}), Object.defineProperty(function WriteStream(options) {
return new InternalWriteStream(options);
}), Object.defineProperty(function WriteStream(path, options) {
return new InternalWriteStream(path, options);
}, Symbol.hasInstance, {
value(instance) {
return instance instanceof InternalWriteStream;

View File

@@ -1068,6 +1068,44 @@ describe("createWriteStream", () => {
expect(exception.code).toBe("ERR_INVALID_ARG_TYPE");
}
});
it("writing in append mode should not truncate the file", async () => {
const path = `${tmpdir()}/fs.test.js/${Date.now()}.createWriteStreamAppend.txt`;
const stream = createWriteStream(path, {
// @ts-ignore-next-line
flags: "a",
});
stream.write("first line\n");
stream.end();
await new Promise((resolve, reject) => {
stream.on("error", e => {
reject(e);
});
stream.on("finish", () => {
resolve(true);
});
});
const stream2 = createWriteStream(path, {
// @ts-ignore-next-line
flags: "a",
});
stream2.write("second line\n");
stream2.end();
return await new Promise((resolve, reject) => {
stream2.on("error", e => {
reject(e);
});
stream2.on("finish", () => {
expect(readFileSync(path, "utf8")).toBe("first line\nsecond line\n");
resolve(true);
});
});
});
});
describe("fs/promises", () => {