Deno.truncate
truncate
-
truncate(name: string, len?: number): Promise<void>
-
通过指定的
len
,截取或者扩展指定的文件内容。如果未指定len
,则整个文件内容将被截取。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 await Deno.truncate("my_file.txt");
//truncate part of the file const file = await Deno.makeTempFile(); await Deno.writeFile(file, new TextEncoder().encode("Hello World")); await Deno.truncate(file, 7); const data = await Deno.readFile(file); console.log(new TextDecoder().decode(data)); //"Hello W"
需要
allow-write
权限。Requires
allow-write
permission.
参数
- ##### name: string
- ##### Optional len: number