Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fa35ba82e |
+2
-2
@@ -7,8 +7,8 @@ const writable = await file_handle.createWritable()
|
|||||||
writable.write('Hello World!')
|
writable.write('Hello World!')
|
||||||
writable.close()
|
writable.close()
|
||||||
const file = await file_handle.getFile()
|
const file = await file_handle.getFile()
|
||||||
const file_text = await file.text()
|
console.log(file.type)
|
||||||
console.log(file_text)
|
console.log(await file.text())
|
||||||
const result = await cwd_directory_handle.getFileHandle('test/test.txt').catch(error => 'blocked path traversal')
|
const result = await cwd_directory_handle.getFileHandle('test/test.txt').catch(error => 'blocked path traversal')
|
||||||
if (typeof result === 'string') console.log(result)
|
if (typeof result === 'string') console.log(result)
|
||||||
else console.error('path traversal not blocked')
|
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 * as path from 'node:path';
|
||||||
import NodeFileSystemHandle from './NodeFileSystemHandle.js';
|
import NodeFileSystemHandle from './NodeFileSystemHandle.js';
|
||||||
import NodeFileSystemWritableFileStream from './NodeFileSystemWriteableFileStream.js';
|
import NodeFileSystemWritableFileStream from './NodeFileSystemWriteableFileStream.js';
|
||||||
|
import mime from 'mime'
|
||||||
|
|
||||||
export default class NodeFileSystemFileHandle extends NodeFileSystemHandle implements FileSystemFileHandle {
|
export default class NodeFileSystemFileHandle extends NodeFileSystemHandle implements FileSystemFileHandle {
|
||||||
declare kind: "file";
|
declare kind: "file";
|
||||||
@@ -18,7 +19,8 @@ export default class NodeFileSystemFileHandle extends NodeFileSystemHandle imple
|
|||||||
}
|
}
|
||||||
async getFile(): Promise<File> {
|
async getFile(): Promise<File> {
|
||||||
const stats = await asyncfs.stat(this.path)
|
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,
|
lastModified: stats.mtimeMs,
|
||||||
name: this.path,
|
name: this.path,
|
||||||
webkitRelativePath: this.path
|
webkitRelativePath: this.path
|
||||||
|
|||||||
Reference in New Issue
Block a user