Skip to content

fix(ext/node): add truncate method to the FileHandle class#27389

Merged
kt3k merged 6 commits intodenoland:mainfrom
filipstev:filipstev/truncate_to_file_handle
Dec 20, 2024
Merged

fix(ext/node): add truncate method to the FileHandle class#27389
kt3k merged 6 commits intodenoland:mainfrom
filipstev:filipstev/truncate_to_file_handle

Conversation

@filipstev
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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
opendir: opendirPromise,
rename: renamePromise,
truncate: truncatePromise,
ftruncate: ftruncatePromise,
Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
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 🧹

export const opendir = fsPromises.opendir;
export const rename = fsPromises.rename;
export const truncate = fsPromises.truncate;
export const ftruncate = fsPromises.ftruncate;
Copy link
Copy Markdown
Contributor

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

}

truncate(len?: number): Promise<void> {
return fsCall(promises.ftruncate, this, len);
Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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
Copy Markdown
Contributor

@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
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