Add API proposal for reading files in data transfer#148596
Conversation
| interface DataTransferFile { | ||
| /** | ||
| * The name of the file. | ||
| */ | ||
| readonly name: string; | ||
|
|
||
| /** | ||
| * The full file path of the file. | ||
| * | ||
| * May be undefined on web. | ||
| */ | ||
| readonly uri?: Uri; | ||
|
|
||
| /** | ||
| * The full file contents of the file. | ||
| */ | ||
| data(): Thenable<Uint8Array>; |
There was a problem hiding this comment.
The dom API returns a File with getAsFile(), so this makes sense to me. However, the dom API offers both a stream() and text() methods on File. Should we also have a stream() method to encourage extension authors not to read whole files into memory? Since the file will need to be transered cross process (or across the network in the case of remote), supporting files at all could be quite expensive and slow.
There was a problem hiding this comment.
I've pushed a change to make the file transfer lazy
However I did not yet add a way to read part of the file contents. Our existing fs apis also only allow working with whole files, so I wanted to stay consistent with them
I definitely think this is something we could add in the future to this api though
Adds a new `DataTransfer.asFile` method which lets you get file objects from a `DataTransfer`. This is currently only hooked up for drop into editors.
A few follow ups:
- Right now the file data is also read eagerly when it is transfered to the extension host. Before shipping this we would make this happen lazily instead
- The drop into editor api does not provide a nice way to do anything with the dropped files.
We should at least support returning a `WorkspaceEdit`. However `WorkspaceEdit` only supports text files, so we would also need to add an API that lets it deal with binary files
`asFile().data()` already returns a promise so `asFile` doesn't also need to be async
7ec6824 to
2ad751d
Compare
|
|
||
| const replacementRange = new vscode.Range(position, position); | ||
|
|
||
| const files: Array<vscode.DataTransferFile> = []; |
There was a problem hiding this comment.
This part of the PR is for testing purposes and should not be merged as is
|
Merging. Will continue testing and polishing this iteration |
Fixes #147481
Adds a new
DataTransfer.asFilemethod which lets you get file objects from aDataTransfer. This is currently only hooked up for drop into editors.A few follow ups:
Right now the file data is also read eagerly when it is transfered to the extension host. Before shipping this we would make this happen lazily instead
The drop into editor api does not provide a nice way to do anything with the dropped files.
We should at least support returning a
WorkspaceEdit. HoweverWorkspaceEditonly supports text files, so we would also need to add an API that lets it deal with binary filesSee Support creating binary files in a WorkspaceEdit #148667