forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: add FileHandle support to Read/WriteStream
Support creating a Read/WriteStream from a FileHandle instead of a raw file descriptor Add an EventEmitter to FileHandle with a single 'close' event Refs: nodejs#35240
- Loading branch information
Showing
6 changed files
with
200 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const fs = require('fs'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const file = path.join(tmpdir.path, '/read_stream_filehandle_test.txt'); | ||
const input = 'hello world'; | ||
|
||
let output = ''; | ||
tmpdir.refresh(); | ||
fs.writeFileSync(file, input); | ||
|
||
fs.promises.open(file, 'r').then((handle) => { | ||
handle.on('close', common.mustCall()); | ||
const stream = fs.createReadStream(null, { fd: handle }); | ||
|
||
stream.on('data', common.mustCallAtLeast((data) => { | ||
output += data; | ||
})); | ||
|
||
stream.on('end', common.mustCall(() => { | ||
assert.strictEqual(output, input); | ||
})); | ||
|
||
stream.on('close', common.mustCall()); | ||
}); | ||
|
||
fs.promises.open(file, 'r').then((handle) => { | ||
handle.on('close', common.mustCall()); | ||
const stream = fs.createReadStream(null, { fd: handle }); | ||
stream.on('data', common.mustNotCall()); | ||
stream.on('close', common.mustCall()); | ||
|
||
handle.close(); | ||
}); | ||
|
||
fs.promises.open(file, 'r').then((handle) => { | ||
assert.throws(() => { | ||
fs.createReadStream(null, { fd: handle, fs }); | ||
}, { | ||
code: 'ERR_METHOD_NOT_IMPLEMENTED', | ||
name: 'Error', | ||
message: 'The FileHandle with fs method is not implemented' | ||
}); | ||
}); |
Oops, something went wrong.