-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
fs/promises
FileHandle does not exist
#19165
Comments
I will work on this |
Hello, This is my first time contributing to Deno's OSS and I have a few questions. Initially, I thought the issue could be resolved by simply adding something to the polyfill. However, I realized that FileHandle is not yet present. I understand that we need to add this and establish a sequence of steps for use with However, I'm currently struggling to understand how Deno achieves Node compatibility. Could you please give me an overview of the architecture regarding this? Also, I believe this document (https://github.com/denoland/deno/tree/main/ext/node/polyfills) is outdated and may not function adequately in its current state. I felt an update might be necessary concerning this. I would like to propose working on fixing this issue. I would appreciate any advice or feedback on how best to proceed. Thank you in advance. |
Hey @k-nasa, thanks for interest in contributing. I will write up a longer rundown of things that need to happen to polyfill this API. I'll get back to you later tonight. |
Thank you for your reply. looking forward to it. @bartlomieju |
@k-nasa so I would suggest to start very small - focus on adding The actual I suggest to skip the Then in Once you get that set up we can think about how to actually implement the API - right now I'm thinking that Let me know if that's helpful or do you need more pointers to get started. |
@bartlomieju Thank you! I think this is enough information to get started. I will try to work on it tonight. From your explanation, it seems that "node compatibility" is not achieved by using Node internally, but by a TypeScript program that provides the same interface and behaves the same way as Node. Is the Rust language included in ext/node closely related to the Deno runtime? |
That's correct, we do not use Node.js internally, but instead provide a set of APIs that are available in Node.js but are implemented internally by Deno - the implementation is different, but the API surface is the same and we try to achieve the same behavior as in Node (though that's not always the case).
|
I am working here
|
@bartlomieju |
<!-- Before submitting a PR, please read https://deno.com/manual/contributing 1. Give the PR a descriptive title. Examples of good title: - fix(std/http): Fix race condition in server - docs(console): Update docstrings - feat(doc): Handle nested reexports Examples of bad title: - fix #7123 - update docs - fix bugs 2. Ensure there is a related issue and it is referenced in the PR text. 3. Ensure there are tests that cover the changes. 4. Ensure `cargo test` passes. 5. Ensure `./tools/format.js` passes without changing files. 6. Ensure `./tools/lint.js` passes. 7. Open as a draft PR if your work is still in progress. The CI won't run all steps, but you can add '[ci]' to a commit message to force it to. 8. If you would like to run the benchmarks on the CI, add the 'ci-bench' label. --> ## WHY ref: #19165 Node's fs/promises includes a FileHandle class, but deno does not. The open function in Node's fs/promises returns a FileHandle, which provides an IO interface to the file. However, deno's open function returns a resource id. ### deno ```js > const fs = await import("node:fs/promises"); undefined > const file3 = await fs.open("./README.md"); undefined > file3 3 > file3.read undefined Node: ``` ### Node ```js > const fs = await import("fs/promises"); undefined > const file3 = await fs.open("./tests/e2e_unit/testdata/file.txt"); undefined > file3 FileHandle { _events: [Object: null prototype] {}, _eventsCount: 0, _maxListeners: undefined, close: [Function: close], [Symbol(kCapture)]: false, [Symbol(kHandle)]: FileHandle {}, [Symbol(kFd)]: 24, [Symbol(kRefs)]: 1, [Symbol(kClosePromise)]: null } > file3.read [Function: read] ``` To be compatible with Node, deno's open function should also return a FileHandle. ## WHAT I have implemented the first step in adding a FileHandle. - Changed the return value of the open function to a FileHandle object - Implemented the readFile method in FileHandle - Add test code ## What to do next This PR is the first step in adding a FileHandle, and there are things that should be done next. - Add functionality equivalent to Node's FileHandle to FileHandle (currently there is only readFile) --------- Co-authored-by: Matt Mastracci <[email protected]>
FileHandle has this many methods FileHandle needs to implement these.
|
## WHY ref: #19165 The FileHandle class has many missing methods compared to node. Add these. ## WHAT - Add close method --------- Co-authored-by: Matt Mastracci <[email protected]>
ref: #19165 The FileHandle class has many missing methods compared to node.
## WHY ref: #19165 The FileHandle class has many missing methods compared to node. ## WHAT Add write method
<!-- Before submitting a PR, please read https://deno.com/manual/contributing 1. Give the PR a descriptive title. Examples of good title: - fix(std/http): Fix race condition in server - docs(console): Update docstrings - feat(doc): Handle nested reexports Examples of bad title: - fix #7123 - update docs - fix bugs 2. Ensure there is a related issue and it is referenced in the PR text. 3. Ensure there are tests that cover the changes. 4. Ensure `cargo test` passes. 5. Ensure `./tools/format.js` passes without changing files. 6. Ensure `./tools/lint.js` passes. 7. Open as a draft PR if your work is still in progress. The CI won't run all steps, but you can add '[ci]' to a commit message to force it to. 8. If you would like to run the benchmarks on the CI, add the 'ci-bench' label. --> ## WHY ref: #19165 Node's fs/promises includes a FileHandle class, but deno does not. The open function in Node's fs/promises returns a FileHandle, which provides an IO interface to the file. However, deno's open function returns a resource id. ### deno ```js > const fs = await import("node:fs/promises"); undefined > const file3 = await fs.open("./README.md"); undefined > file3 3 > file3.read undefined Node: ``` ### Node ```js > const fs = await import("fs/promises"); undefined > const file3 = await fs.open("./tests/e2e_unit/testdata/file.txt"); undefined > file3 FileHandle { _events: [Object: null prototype] {}, _eventsCount: 0, _maxListeners: undefined, close: [Function: close], [Symbol(kCapture)]: false, [Symbol(kHandle)]: FileHandle {}, [Symbol(kFd)]: 24, [Symbol(kRefs)]: 1, [Symbol(kClosePromise)]: null } > file3.read [Function: read] ``` To be compatible with Node, deno's open function should also return a FileHandle. ## WHAT I have implemented the first step in adding a FileHandle. - Changed the return value of the open function to a FileHandle object - Implemented the readFile method in FileHandle - Add test code ## What to do next This PR is the first step in adding a FileHandle, and there are things that should be done next. - Add functionality equivalent to Node's FileHandle to FileHandle (currently there is only readFile) --------- Co-authored-by: Matt Mastracci <[email protected]>
## WHY ref: #19165 The FileHandle class has many missing methods compared to node. Add these. ## WHAT - Add close method --------- Co-authored-by: Matt Mastracci <[email protected]>
ref: #19165 The FileHandle class has many missing methods compared to node.
## WHY ref: #19165 The FileHandle class has many missing methods compared to node. ## WHAT Add write method
Created #25554 for better visibility. Closing this one as the original issue has been resolved |
Deno:
Node:
The text was updated successfully, but these errors were encountered: