| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,14 +7,14 @@ const tmpdir = require('../common/tmpdir'); | |||
| 7 | 7 | const file = path.join(tmpdir.path, 'read_stream_filehandle_test.txt'); | |
| 8 | 8 | const input = 'hello world'; | |
| 9 | 9 | ||
| 10 | - let output = ''; | ||
| 11 | 10 | tmpdir.refresh(); | |
| 12 | 11 | fs.writeFileSync(file, input); | |
| 13 | 12 | ||
| 14 | - fs.promises.open(file, 'r').then(common.mustCall((handle) => { | ||
| 13 | + fs.promises.open(file, 'r').then((handle) => { | ||
| 15 | 14 | handle.on('close', common.mustCall()); | |
| 16 | 15 | const stream = fs.createReadStream(null, { fd: handle }); | |
| 17 | 16 | ||
| 17 | + let output = ''; | ||
| 18 | 18 | stream.on('data', common.mustCallAtLeast((data) => { | |
| 19 | 19 | output += data; | |
| 20 | 20 | })); | |
@@ -24,42 +24,60 @@ fs.promises.open(file, 'r').then(common.mustCall((handle) => { | |||
| 24 | 24 | })); | |
| 25 | 25 | ||
| 26 | 26 | stream.on('close', common.mustCall()); | |
| 27 | - })); | ||
| 27 | + }).then(common.mustCall()); | ||
| 28 | 28 | ||
| 29 | - fs.promises.open(file, 'r').then(common.mustCall((handle) => { | ||
| 29 | + fs.promises.open(file, 'r').then((handle) => { | ||
| 30 | 30 | handle.on('close', common.mustCall()); | |
| 31 | 31 | const stream = fs.createReadStream(null, { fd: handle }); | |
| 32 | 32 | stream.on('data', common.mustNotCall()); | |
| 33 | 33 | stream.on('close', common.mustCall()); | |
| 34 | 34 | ||
| 35 | - handle.close(); | ||
| 36 | - })); | ||
| 35 | + return handle.close(); | ||
| 36 | + }).then(common.mustCall()); | ||
| 37 | 37 | ||
| 38 | - fs.promises.open(file, 'r').then(common.mustCall((handle) => { | ||
| 38 | + fs.promises.open(file, 'r').then((handle) => { | ||
| 39 | 39 | handle.on('close', common.mustCall()); | |
| 40 | 40 | const stream = fs.createReadStream(null, { fd: handle }); | |
| 41 | 41 | stream.on('close', common.mustCall()); | |
| 42 | 42 | ||
| 43 | 43 | stream.on('data', common.mustCall(() => { | |
| 44 | 44 | handle.close(); | |
| 45 | 45 | })); | |
| 46 | - })); | ||
| 46 | + }).then(common.mustCall()); | ||
| 47 | 47 | ||
| 48 | - fs.promises.open(file, 'r').then(common.mustCall((handle) => { | ||
| 48 | + fs.promises.open(file, 'r').then((handle) => { | ||
| 49 | 49 | handle.on('close', common.mustCall()); | |
| 50 | 50 | const stream = fs.createReadStream(null, { fd: handle }); | |
| 51 | 51 | stream.on('close', common.mustCall()); | |
| 52 | 52 | ||
| 53 | 53 | stream.close(); | |
| 54 | - })); | ||
| 54 | + }).then(common.mustCall()); | ||
| 55 | 55 | ||
| 56 | - fs.promises.open(file, 'r').then(common.mustCall((handle) => { | ||
| 56 | + fs.promises.open(file, 'r').then((handle) => { | ||
| 57 | 57 | assert.throws(() => { | |
| 58 | 58 | fs.createReadStream(null, { fd: handle, fs }); | |
| 59 | 59 | }, { | |
| 60 | 60 | code: 'ERR_METHOD_NOT_IMPLEMENTED', | |
| 61 | 61 | name: 'Error', | |
| 62 | 62 | message: 'The FileHandle with fs method is not implemented' | |
| 63 | 63 | }); | |
| 64 | - handle.close(); | ||
| 65 | - })); | ||
| 64 | + return handle.close(); | ||
| 65 | + }).then(common.mustCall()); | ||
| 66 | + | ||
| 67 | + fs.promises.open(file, 'r').then((handle) => { | ||
| 68 | + const { read: originalReadFunction } = handle; | ||
| 69 | + handle.read = common.mustCallAtLeast(function read() { | ||
| 70 | + return Reflect.apply(originalReadFunction, this, arguments); | ||
| 71 | + }); | ||
| 72 | + | ||
| 73 | + const stream = fs.createReadStream(null, { fd: handle }); | ||
| 74 | + | ||
| 75 | + let output = ''; | ||
| 76 | + stream.on('data', common.mustCallAtLeast((data) => { | ||
| 77 | + output += data; | ||
| 78 | + })); | ||
| 79 | + | ||
| 80 | + stream.on('end', common.mustCall(() => { | ||
| 81 | + assert.strictEqual(output, input); | ||
| 82 | + })); | ||
| 83 | + }).then(common.mustCall()); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ const input = 'hello world'; | |||
| 9 | 9 | ||
| 10 | 10 | tmpdir.refresh(); | |
| 11 | 11 | ||
| 12 | - fs.promises.open(file, 'w+').then(common.mustCall((handle) => { | ||
| 12 | + fs.promises.open(file, 'w+').then((handle) => { | ||
| 13 | 13 | handle.on('close', common.mustCall()); | |
| 14 | 14 | const stream = fs.createWriteStream(null, { fd: handle }); | |
| 15 | 15 | ||
@@ -18,4 +18,27 @@ fs.promises.open(file, 'w+').then(common.mustCall((handle) => { | |||
| 18 | 18 | const output = fs.readFileSync(file, 'utf-8'); | |
| 19 | 19 | assert.strictEqual(output, input); | |
| 20 | 20 | })); | |
| 21 | - })); | ||
| 21 | + }).then(common.mustCall()); | ||
| 22 | + | ||
| 23 | + fs.promises.open(file, 'w+').then((handle) => { | ||
| 24 | + let calls = 0; | ||
| 25 | + const { | ||
| 26 | + write: originalWriteFunction, | ||
| 27 | + writev: originalWritevFunction | ||
| 28 | + } = handle; | ||
| 29 | + handle.write = function write() { | ||
| 30 | + calls++; | ||
| 31 | + return Reflect.apply(originalWriteFunction, this, arguments); | ||
| 32 | + }; | ||
| 33 | + handle.writev = function writev() { | ||
| 34 | + calls++; | ||
| 35 | + return Reflect.apply(originalWritevFunction, this, arguments); | ||
| 36 | + }; | ||
| 37 | + const stream = fs.createWriteStream(null, { fd: handle }); | ||
| 38 | + | ||
| 39 | + stream.end(input); | ||
| 40 | + stream.on('close', common.mustCall(() => { | ||
| 41 | + assert(calls > 0, 'expected at least one call to fileHandle.write or ' + | ||
| 42 | + 'fileHandle.writev, got 0'); | ||
| 43 | + })); | ||
| 44 | + }).then(common.mustCall()); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments