// NOTE: Below read size is derived from the high water mark in core lib/internal/fs/streams.js
letdefaultChunkSize=64*1024;
functiondoRead(handle,length){
// TODO: Can we safely switch to `allocUnsafe` here?
letbuffer=Buffer.alloc(length);
returnPromise.try(()=>{
returnhandle.read(buffer,0,length);
}).then((result)=>{
if(result.bytesRead===0){
// Not documented; https://github.com/nodejs/node/issues/35363
thrownewEndOfStream();
}elseif(result.bytesRead===length){
returnbuffer;
}elseif(result.bytesRead<length){
// TODO: For possible future performance optimization, consider reusing the remaining Buffer allocation for a next read, if possible. Need more data on how often this case occurs first, though, to justify the added complexity.