|
|
@ -266,6 +266,7 @@ function fromBytes(buffer: FixedSizeArray<number, 8>): number {
|
|
|
|
const size = bytes.byteLength
|
|
|
|
const size = bytes.byteLength
|
|
|
|
let x = 0
|
|
|
|
let x = 0
|
|
|
|
for (let i = 0; i < size; i++) {
|
|
|
|
for (let i = 0; i < size; i++) {
|
|
|
|
|
|
|
|
// eslint-disable-next-line security/detect-object-injection
|
|
|
|
const byte = bytes[i]
|
|
|
|
const byte = bytes[i]
|
|
|
|
x *= 0x100
|
|
|
|
x *= 0x100
|
|
|
|
x += byte
|
|
|
|
x += byte
|
|
|
@ -427,11 +428,11 @@ class FileHandle extends Resource {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Writes `p.byteLength` bytes from `p` to the underlying data stream. It
|
|
|
|
* Writes `data.byteLength` bytes from `data` to the underlying data stream. It
|
|
|
|
* resolves to the number of bytes written from `p` (`0` <= `n` <=
|
|
|
|
* resolves to the number of bytes written from `data` (`0` <= `n` <=
|
|
|
|
* `p.byteLength`) or reject with the error encountered that caused the
|
|
|
|
* `data.byteLength`) or reject with the error encountered that caused the
|
|
|
|
* write to stop early. `write()` must reject with a non-null error if
|
|
|
|
* write to stop early. `write()` must reject with a non-null error if
|
|
|
|
* would resolve to `n` < `p.byteLength`. `write()` must not modify the
|
|
|
|
* would resolve to `n` < `data.byteLength`. `write()` must not modify the
|
|
|
|
* slice data, even temporarily.
|
|
|
|
* slice data, even temporarily.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* @example
|
|
|
@ -1044,19 +1045,27 @@ interface WriteFileOptions {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async function writeFile(
|
|
|
|
async function writeFile(
|
|
|
|
path: string | URL,
|
|
|
|
path: string | URL,
|
|
|
|
data: Uint8Array,
|
|
|
|
data: Uint8Array | ReadableStream<Uint8Array>,
|
|
|
|
options?: WriteFileOptions
|
|
|
|
options?: WriteFileOptions
|
|
|
|
): Promise<void> {
|
|
|
|
): Promise<void> {
|
|
|
|
if (path instanceof URL && path.protocol !== 'file:') {
|
|
|
|
if (path instanceof URL && path.protocol !== 'file:') {
|
|
|
|
throw new TypeError('Must be a file URL.')
|
|
|
|
throw new TypeError('Must be a file URL.')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await invoke('plugin:fs|write_file', data, {
|
|
|
|
if (data instanceof ReadableStream) {
|
|
|
|
headers: {
|
|
|
|
const file = await open(path, options)
|
|
|
|
path: encodeURIComponent(path instanceof URL ? path.toString() : path),
|
|
|
|
for await (const chunk of data) {
|
|
|
|
options: JSON.stringify(options)
|
|
|
|
await file.write(chunk)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
await file.close()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
await invoke('plugin:fs|write_file', data, {
|
|
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
|
|
path: encodeURIComponent(path instanceof URL ? path.toString() : path),
|
|
|
|
|
|
|
|
options: JSON.stringify(options)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|