-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.stale
Description
It might be possible to have a more efficient way to pipe a file to a stream by adding a .stream
method to FileHandle
.
e.g.
FileHandle.prototype.stream = async function (dst, { start = 0, end, signal } = {}) {
// TODO: this[kRef](), this[kUnref](), if (signal.aborted) throw AbortError()
let pos = start
while (true) {
if (end && pos >= end) {
break
}
const { buffer, bytesRead } = await this.read({
buffer: Buffer.allocUnsafe(Math.min(end - pos, 16384)),
position: pos,
})
if (bytesRead === 0) {
break
}
if (dst.writableNeedDrain) {
await EE.once(res, 'drain', { signal })
}
if (dst.destroyed) {
break // TODO: break or throw?
}
dst.write(buffer)
pos += bytesRead
}
}
const fileHandle = fsp.open(filePath)
try {
await fileHandle.stream(dst)
} finally {
await fileHandle.close()
}
vs
await pipeline(fs.createReadStream(filePath), dst)
Less ergonomic but potentially better performance. This idea needs benchmarking.
aduh95, RaisinTen, yagipy and sambhavsaxena
Metadata
Metadata
Assignees
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.stale