This commit is contained in:
+2
-2
@@ -7,8 +7,8 @@ const writable = await file_handle.createWritable()
|
||||
writable.write('Hello World!')
|
||||
writable.close()
|
||||
const file = await file_handle.getFile()
|
||||
const file_text = await file.text()
|
||||
console.log(file_text)
|
||||
console.log(file.type)
|
||||
console.log(await file.text())
|
||||
const result = await cwd_directory_handle.getFileHandle('test/test.txt').catch(error => 'blocked path traversal')
|
||||
if (typeof result === 'string') console.log(result)
|
||||
else console.error('path traversal not blocked')
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as asyncfs from 'node:fs/promises';
|
||||
import * as path from 'node:path';
|
||||
import NodeFileSystemHandle from './NodeFileSystemHandle.js';
|
||||
import NodeFileSystemWritableFileStream from './NodeFileSystemWriteableFileStream.js';
|
||||
import mime from 'mime'
|
||||
|
||||
export default class NodeFileSystemFileHandle extends NodeFileSystemHandle implements FileSystemFileHandle {
|
||||
declare kind: "file";
|
||||
@@ -18,7 +19,8 @@ export default class NodeFileSystemFileHandle extends NodeFileSystemHandle imple
|
||||
}
|
||||
async getFile(): Promise<File> {
|
||||
const stats = await asyncfs.stat(this.path)
|
||||
return asyncfs.readFile(this.path).then(buffer => Object.assign(new Blob([buffer]), {
|
||||
const type = mime.getType(this.name.split('.').pop())
|
||||
return asyncfs.readFile(this.path).then(buffer => Object.assign(new Blob([buffer],{type}), {
|
||||
lastModified: stats.mtimeMs,
|
||||
name: this.path,
|
||||
webkitRelativePath: this.path
|
||||
|
||||
Reference in New Issue
Block a user