Skip to content
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

Merged
merged 6 commits into from
Dec 20, 2024

Conversation

filipstev
Copy link
Contributor

@filipstev filipstev commented Dec 16, 2024

  • Implements FileHandle.truncate
  • Adds a promisified fs.ftruncate under fs/promises which is used internally by FileHandle.ftruncate
  • Adds a couple of formatting changes due to running ./tools/format.js
  • Adds tests
  • filehandle.truncate Node documentation: click here

part of #25554

@CLAassistant
Copy link

CLAassistant commented Dec 16, 2024

CLA assistant check
All committers have signed the CLA.

@filipstev filipstev changed the title feat(node_compat): Add a truncate method to the FileHandle class feat(node_compat): Add truncate method to the FileHandle class Dec 16, 2024
@filipstev
Copy link
Contributor Author

Hey @kt3k, sorry for pinging you, could you take a look at this PR?
Happy to keep working on it if there are any further suggestions!

@kt3k kt3k mentioned this pull request Dec 19, 2024
24 tasks
@@ -165,6 +169,7 @@ const promises = {
opendir: opendirPromise,
rename: renamePromise,
truncate: truncatePromise,
ftruncate: ftruncatePromise,
Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Contributor Author

@filipstev filipstev Dec 19, 2024

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 🧹

@@ -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;
Copy link
Member

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);
Copy link
Member

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"

@kt3k
Copy link
Member

kt3k commented Dec 19, 2024

Thanks for the PR!

The test cases look good. I left some comments.

@kt3k kt3k changed the title feat(node_compat): Add truncate method to the FileHandle class fix(ext/node): add truncate method to the FileHandle class Dec 19, 2024
Copy link
Member

@kt3k kt3k left a 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

@kt3k kt3k merged commit 23f7032 into denoland:main Dec 20, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants