From f283cda399da8fbbe3c8a1a1eabcaaea7312d0b0 Mon Sep 17 00:00:00 2001 From: Dylan Conway Date: Wed, 1 Jan 2025 13:00:17 -0800 Subject: [PATCH] fix test-fs-assert-encoding-error.js --- src/js/node/fs.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/js/node/fs.ts b/src/js/node/fs.ts index 88b1b7aab3..a66e01d44f 100644 --- a/src/js/node/fs.ts +++ b/src/js/node/fs.ts @@ -763,6 +763,12 @@ function ReadStream(this: typeof ReadStream, pathOrFd, options) { options = { encoding: options }; } + if (options.encoding && options.encoding !== "buffer") { + if (!Buffer.isEncoding(options.encoding)) { + throw $ERR_INVALID_ARG_VALUE("encoding", options.encoding, "is invalid encoding"); + } + } + if (!$isObject(options) && !$isCallable(options)) { throw new TypeError("Expected options to be an object or a string"); } @@ -1070,6 +1076,16 @@ var WriteStreamClass = (WriteStream = function WriteStream(path, options = defau throw new TypeError("Expected options to be an object"); } + if (typeof options === "string") { + options = { encoding: options }; + } + + if (options.encoding && options.encoding !== "buffer") { + if (!Buffer.isEncoding(options.encoding)) { + throw $ERR_INVALID_ARG_VALUE("encoding", options.encoding, "is invalid encoding"); + } + } + var { fs = defaultWriteStreamOptions.fs, start = defaultWriteStreamOptions.start,