-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
fix(ext/node): add truncate
method to the FileHandle
class
#27389
fix(ext/node): add truncate
method to the FileHandle
class
#27389
Conversation
truncate
method to the FileHandle
class
Hey @kt3k, sorry for pinging you, could you take a look at this PR? |
ext/node/polyfills/fs.ts
Outdated
@@ -165,6 +169,7 @@ const promises = { | |||
opendir: opendirPromise, | |||
rename: renamePromise, | |||
truncate: truncatePromise, | |||
ftruncate: ftruncatePromise, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node doesn't seem having fs.promises.ftruncate
(No doc entry for it, and also not available in runtime) https://nodejs.org/api/fs.html
Let's not expose it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You make a great point! I've noticed that fstat
is also exposed but can't seem to find it in the doc, and fs.promises.fstat
also doesn't seem to be available in the runtime. Is that an issue, and if so, is it something we would like to handle within this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fstat is also exposed but can't seem to find it in the doc, and fs.promises.fstat also doesn't seem to be available in the runtime. Is that an issue
Good point. Yes, that seems an issue to me.
, and if so, is it something we would like to handle within this PR?
Fixing it in this PR is welcome, but that's not absolutely necessary in my opinon. I created an issue for fs.promises.fstat
for now #27423
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, I might take a deeper look into that one as well, see if we might have more to clean up :)
Also, the implementation for promises.ftruncate
has been cleaned up 🧹
ext/node/polyfills/fs/promises.ts
Outdated
@@ -8,6 +8,7 @@ export const open = fsPromises.open; | |||
export const opendir = fsPromises.opendir; | |||
export const rename = fsPromises.rename; | |||
export const truncate = fsPromises.truncate; | |||
export const ftruncate = fsPromises.ftruncate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto. Let's not expose this
@@ -73,6 +73,10 @@ export class FileHandle extends EventEmitter { | |||
} | |||
} | |||
|
|||
truncate(len?: number): Promise<void> { | |||
return fsCall(promises.ftruncate, this, len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably we need to import ftruncatePromise
directly from "ext:deno_node/_fs/_fs_ftruncate.ts"
Thanks for the PR! The test cases look good. I left some comments. |
truncate
method to the FileHandle
classtruncate
method to the FileHandle
class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Nice work! Thanks for your contribution
FileHandle.truncate
fs.ftruncate
underfs/promises
which is used internally byFileHandle.ftruncate
./tools/format.js
filehandle.truncate
Node documentation: click herepart of #25554