Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2c2b07c

Browse filesBrowse files
debadree25RafaelGSS
authored andcommitted
fs: invalidate blob created from empty file when written to
Fixes: #47161 PR-URL: #47199 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 3f49da5 commit 2c2b07c
Copy full SHA for 2c2b07c

File tree

Expand file treeCollapse file tree

2 files changed

+20
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-12
lines changed
Open diff view settings
Collapse file

‎lib/internal/blob.js‎

Copy file name to clipboardExpand all lines: lib/internal/blob.js
-12Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
'use strict';
22

33
const {
4-
ArrayBuffer,
54
ArrayFrom,
65
MathMax,
76
MathMin,
87
ObjectDefineProperties,
98
ObjectDefineProperty,
109
PromiseReject,
11-
PromiseResolve,
1210
ReflectConstruct,
1311
RegExpPrototypeExec,
1412
RegExpPrototypeSymbolReplace,
@@ -266,10 +264,6 @@ class Blob {
266264
if (!isBlob(this))
267265
return PromiseReject(new ERR_INVALID_THIS('Blob'));
268266

269-
if (this.size === 0) {
270-
return PromiseResolve(new ArrayBuffer(0));
271-
}
272-
273267
const { promise, resolve, reject } = createDeferredPromise();
274268
const reader = this[kHandle].getReader();
275269
const buffers = [];
@@ -316,12 +310,6 @@ class Blob {
316310
if (!isBlob(this))
317311
throw new ERR_INVALID_THIS('Blob');
318312

319-
if (this.size === 0) {
320-
return new lazyReadableStream({
321-
start(c) { c.close(); },
322-
});
323-
}
324-
325313
const reader = this[kHandle].getReader();
326314
return new lazyReadableStream({
327315
start(c) {
Collapse file

‎test/parallel/test-blob-file-backed.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-blob-file-backed.js
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ const { Blob } = require('buffer');
2020
const tmpdir = require('../common/tmpdir');
2121
const testfile = path.join(tmpdir.path, 'test-file-backed-blob.txt');
2222
const testfile2 = path.join(tmpdir.path, 'test-file-backed-blob2.txt');
23+
const testfile3 = path.join(tmpdir.path, 'test-file-backed-blob3.txt');
2324
tmpdir.refresh();
2425

2526
const data = `${'a'.repeat(1000)}${'b'.repeat(2000)}`;
2627

2728
writeFileSync(testfile, data);
2829
writeFileSync(testfile2, data.repeat(100));
30+
writeFileSync(testfile3, '');
2931

3032
(async () => {
3133
const blob = await openAsBlob(testfile);
@@ -79,3 +81,21 @@ writeFileSync(testfile2, data.repeat(100));
7981

8082
await unlink(testfile2);
8183
})().then(common.mustCall());
84+
85+
(async () => {
86+
const blob = await openAsBlob(testfile3);
87+
strictEqual(blob.size, 0);
88+
strictEqual(await blob.text(), '');
89+
writeFileSync(testfile3, 'abc');
90+
await rejects(blob.text(), { name: 'NotReadableError' });
91+
await unlink(testfile3);
92+
})().then(common.mustCall());
93+
94+
(async () => {
95+
const blob = await openAsBlob(testfile3);
96+
strictEqual(blob.size, 0);
97+
writeFileSync(testfile3, 'abc');
98+
const stream = blob.stream();
99+
const reader = stream.getReader();
100+
await rejects(() => reader.read(), { name: 'NotReadableError' });
101+
})().then(common.mustCall());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.