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

more ways of getting files #49757

Closed
3 tasks
jimmywarting opened this issue Sep 21, 2023 · 4 comments
Closed
3 tasks

more ways of getting files #49757

jimmywarting opened this issue Sep 21, 2023 · 4 comments
Labels
feature request Issues that request new features to be added to Node.js. fs Issues and PRs related to the fs subsystem / file system. stale

Comments

@jimmywarting
Copy link

jimmywarting commented Sep 21, 2023

What is the problem this feature will solve?

it's kind of a #developer-pain that

  1. there are no sync version of fs.openAsBlob (aka: fs.openAsBlobSync)
  2. they are a Blob instead of Files and therefore lacks a file name and lastModified. So upgrading them to a File requires figuring out more stuff yourself.

What is the feature you are proposing to solve the problem?

That we add:

What alternatives have you considered?

Only workaround today is to do:

const name = path.basename(filePath)
const stat = fs.statSync(filePath)
const blob = await fs.openAsBlob(filePath)
const file = new File([blob], name, { 
  type: blob.type,
  lastModified: Number(stat.mtime)
 })

would be a heck a lot easier if i could just do:

const file = fs.openAsFileSync(filePath)

and there is no way of getting around it cuz the async openAsBlob is the only thing you can work with. which makes your own code having to be async as well.

@jimmywarting jimmywarting added the feature request Issues that request new features to be added to Node.js. label Sep 21, 2023
@LiviaMedeiros LiviaMedeiros added the fs Issues and PRs related to the fs subsystem / file system. label Sep 22, 2023
@LiviaMedeiros
Copy link
Contributor

LiviaMedeiros commented Sep 22, 2023

The fs.openAsBlob should be moved to Promises API and fs.openAsBlobSync should exist indeed. Drafted #49759 to address this.

 const name = path.basename(filePath)
 const stat = fs.statSync(filePath)
 const blob = await fs.openAsBlob(filePath)
 const file = new File([blob], name, {
-  type: blob.type, // this is always empty string
+  type: userProvidedMimeType,
   lastModified: Number(stat.mtime)
  })

This makes me wonder, wouldn't it be inconsistent that we set lastModified automatically but don't do that with type (using extension-mime map or libmagic)? Because the guessing should probably be done in userland.
type property is read-only; so user wouldn't be able to set it after reading returned File, and fs.readAsFile(path, { type }) would work only if they know type beforehand.

@jimmywarting
Copy link
Author

jimmywarting commented Sep 23, 2023

The fs.openAsBlob should be moved to Promises API

Don't mind that

Drafted #49759 to address this.

👍

I would not mind if it was able to guess the correct type.
I think the mimesniff spec is being used on many web related things... such as
whatwg/fs and <input type="file"> are able to figure out some common types when getting access to a File

But i think we could focus on that later, it dose not really affect this issue directly.
i would say that is a blocker if NodeJS dose not have a built in mime sniffer.
(just created: #49843)

Copy link
Contributor

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label Mar 23, 2024
Copy link
Contributor

There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. fs Issues and PRs related to the fs subsystem / file system. stale
Projects
None yet
Development

No branches or pull requests

2 participants