-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
stdio: implement manual start for ReadStream #36277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,7 +203,8 @@ function Readable(options) { | |
Stream.call(this, options); | ||
|
||
destroyImpl.construct(this, () => { | ||
maybeReadMore(this, this._readableState); | ||
if (!options || !options.manualStart) | ||
ronag marked this conversation as resolved.
Show resolved
Hide resolved
|
||
maybeReadMore(this, this._readableState); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs some tests that are specific to streams. How is a user of Stream be able to use this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mcollina @joyeecheung @ronag @mscdex Attaching a The reason I did in To move this to So two options:
It is also worth noting that there are two other
ronag marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const process = require('process'); | ||
|
||
let defaultShell; | ||
if (process.platform === 'linux' || process.platform === 'darwin') { | ||
defaultShell = '/bin/sh'; | ||
} else if (process.platform === 'win32') { | ||
defaultShell = 'cmd.exe'; | ||
} else { | ||
common.skip('This is test exists only on Linux/Win32/OSX'); | ||
} | ||
|
||
const { execSync } = require('child_process'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const tmpdir = require('../common/tmpdir'); | ||
|
||
const tmpDir = tmpdir.path; | ||
tmpdir.refresh(); | ||
const tmpCmdFile = path.join(tmpDir, 'test-stdin-from-file-spawn-cmd'); | ||
const tmpJsFile = path.join(tmpDir, 'test-stdin-from-file-spawn.js'); | ||
fs.writeFileSync(tmpCmdFile, 'echo hello'); | ||
fs.writeFileSync(tmpJsFile, ` | ||
'use strict'; | ||
const { spawn } = require('child_process'); | ||
// Reference the object to invoke the getter | ||
process.stdin; | ||
setTimeout(() => { | ||
let ok = false; | ||
const child = spawn(process.env.SHELL || '${defaultShell}', | ||
[], { stdio: ['inherit', 'pipe'] }); | ||
child.stdout.on('data', () => { | ||
ok = true; | ||
}); | ||
child.on('close', () => { | ||
process.exit(ok ? 0 : -1); | ||
}); | ||
}, 100); | ||
`); | ||
|
||
execSync(`${process.argv[0]} ${tmpJsFile} < ${tmpCmdFile}`); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
|
||
fs.promises.open(__filename).then(common.mustCall((fd) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are you using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because a cook who doesn't eat its own food is not a good cook 😄 |
||
const rs = new fs.ReadStream(null, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
How is that relevant? It behaves the same as ReadStream. The same test should apply. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If that was true, you'd not need to modify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe there is some biggus problem, how do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Likely, but it's possible to add an independent test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused what the problem here is? We just need change ReadStream to Readable. What is the "biggus" problem? |
||
fd: fd, | ||
manualStart: false | ||
}); | ||
setTimeout(() => assert(rs.bytesRead > 0), common.platformTimeout(10)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be a setImmediate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The read handler is already in a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for the clarification. Maybe add this in a comment? |
||
})); | ||
|
||
fs.promises.open(__filename).then(common.mustCall((fd) => { | ||
const rs = new fs.ReadStream(null, { | ||
fd: fd, | ||
manualStart: true | ||
}); | ||
setTimeout(() => assert(rs.bytesRead === 0), common.platformTimeout(10)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. his should be a setImmediate |
||
})); |
Uh oh!
There was an error while loading. Please reload this page.