mirror of
https://github.com/denoland/deno.git
synced 2025-09-28 05:04:48 +00:00
feat(unstable): add Deno.ftruncate and ftruncateSync (#6243)
This commit is contained in:
parent
bdf2d26ba1
commit
86f92e04c7
5 changed files with 139 additions and 0 deletions
39
cli/js/lib.deno.unstable.d.ts
vendored
39
cli/js/lib.deno.unstable.d.ts
vendored
|
@ -1248,4 +1248,43 @@ declare namespace Deno {
|
|||
|
||||
/** **UNSTABLE**: The URL of the file that was originally executed from the command-line. */
|
||||
export const mainModule: string;
|
||||
|
||||
/** Synchronously truncates or extends the specified file stream, to reach the
|
||||
* specified `len`. If `len` is not specified then the entire file contents
|
||||
* are truncated.
|
||||
*
|
||||
* ```ts
|
||||
* // truncate the entire file
|
||||
* const file = Deno.open("my_file.txt", { read: true, write: true, truncate: true, create: true });
|
||||
* Deno.ftruncateSync(file.rid);
|
||||
*
|
||||
* // truncate part of the file
|
||||
* const file = Deno.open("my_file.txt", { read: true, write: true, create: true });
|
||||
* Deno.write(file.rid, new TextEncoder().encode("Hello World"));
|
||||
* Deno.ftruncateSync(file.rid, 7);
|
||||
* const data = new Uint8Array(32);
|
||||
* Deno.readSync(file.rid, data);
|
||||
* console.log(new TextDecoder().decode(data)); // Hello W
|
||||
* ```
|
||||
*/
|
||||
export function ftruncateSync(rid: number, len?: number): void;
|
||||
|
||||
/** Truncates or extends the specified file stream, to reach the specified `len`. If
|
||||
* `len` is not specified then the entire file contents are truncated.
|
||||
*
|
||||
* ```ts
|
||||
* // truncate the entire file
|
||||
* const file = Deno.open("my_file.txt", { read: true, write: true, create: true });
|
||||
* await Deno.ftruncate(file.rid);
|
||||
*
|
||||
* // truncate part of the file
|
||||
* const file = Deno.open("my_file.txt", { read: true, write: true, create: true });
|
||||
* await Deno.write(file.rid, new TextEncoder().encode("Hello World"));
|
||||
* await Deno.ftruncate(file.rid, 7);
|
||||
* const data = new Uint8Array(32);
|
||||
* await Deno.read(file.rid, data);
|
||||
* console.log(new TextDecoder().decode(data)); // Hello W
|
||||
* ```
|
||||
*/
|
||||
export function ftruncate(rid: number, len?: number): Promise<void>;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue