+9
-6
@@ -1,14 +1,17 @@
|
|||||||
import NodeFileSystemDirectoryHandle from '../dist/NodeFileSystemDirectoryHandle.js'
|
import NodeFileSystemDirectoryHandle from '../src/NodeFileSystemDirectoryHandle.ts'
|
||||||
|
|
||||||
|
const textText="Hello World!"
|
||||||
const cwd_directory_handle = new NodeFileSystemDirectoryHandle('.')
|
const cwd_directory_handle = new NodeFileSystemDirectoryHandle('.')
|
||||||
const test_directory_handle = await cwd_directory_handle.getDirectoryHandle('test', { 'create': true })
|
const test_directory_handle = await cwd_directory_handle.getDirectoryHandle('test', { 'create': true })
|
||||||
const file_handle = await test_directory_handle.getFileHandle('test.txt', { 'create': true })
|
for (let i = 0; i < 10000; i++) {
|
||||||
|
const file_handle = await test_directory_handle.getFileHandle(i+'.txt', { 'create': true })
|
||||||
const writable = await file_handle.createWritable()
|
const writable = await file_handle.createWritable()
|
||||||
writable.write('Hello World!')
|
await writable.write('Hello World!')
|
||||||
writable.close()
|
await writable.close()
|
||||||
const file = await file_handle.getFile()
|
const file = await file_handle.getFile()
|
||||||
console.log(file.type)
|
const text = await file.text()
|
||||||
console.log(await file.text())
|
if(text!==textText) throw new Error("failed to read back written data")
|
||||||
|
}
|
||||||
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')
|
||||||
|
|||||||
@@ -44,17 +44,4 @@ export default class NodeFileSystemWritableFileStream extends WritableStream imp
|
|||||||
fs.writeSync(this.#fd, (wdata as Uint8Array), null, wsize, this.#seek_position)
|
fs.writeSync(this.#fd, (wdata as Uint8Array), null, wsize, this.#seek_position)
|
||||||
this.#seek_position = pseek_position
|
this.#seek_position = pseek_position
|
||||||
}
|
}
|
||||||
async #_close() {
|
|
||||||
try {
|
|
||||||
fs.closeSync(this.#fd)
|
|
||||||
} catch { }
|
|
||||||
}
|
|
||||||
async close(): Promise<void> {
|
|
||||||
await super.close()
|
|
||||||
await this.#_close()
|
|
||||||
}
|
|
||||||
async abort(reason?: any): Promise<void> {
|
|
||||||
await super.abort(reason)
|
|
||||||
await this.#_close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user