Deno.truncatesync
truncateSync
-
truncateSync(name: string, len?: number): void
-
同步地通过指定的
len
,截取或者扩展指定的文件内容。如果未指定len
,则整个文件内容将被截取。Synchronously truncates or extends the specified file, to reach the specified
len
. Iflen
is not specified then the entire file contents are truncated.//truncate the entire file Deno.truncateSync("my_file.txt");
//truncate part of the file const file = Deno.makeTempFileSync(); Deno.writeFileSync(file, new TextEncoder().encode("Hello World")); Deno.truncateSync(file, 7); const data = Deno.readFileSync(file); console.log(new TextDecoder().decode(data));
需要
allow-write
权限。Requires
allow-write
permission.
参数
- ##### name: string
- ##### Optional len: number