Skip to main content
Module

x/netzo/deno.d.ts>Deno.ftruncateSync

SDK for Netzo, the open Web platform to unify IoT devices, applications and services.
Go to Latest
function Deno.ftruncateSync
import { Deno } from "https://deno.land/x/netzo@v0.1.10/deno.d.ts";
const { ftruncateSync } = Deno;

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 as if len was set to 0.

if the file previously was larger than this new length, the extra data is lost.

if the file previously was shorter, it is extended, and the extended part reads as null bytes ('\0').

// truncate the entire file
const file = Deno.openSync("my_file.txt", { read: true, write: true, truncate: true, create: true });
Deno.ftruncateSync(file.rid);
// truncate part of the file
const file = Deno.openSync("my_file.txt", { read: true, write: true, create: true });
Deno.writeSync(file.rid, new TextEncoder().encode("Hello World"));
Deno.ftruncateSync(file.rid, 7);
Deno.seekSync(file.rid, 0, Deno.SeekMode.Start);
const data = new Uint8Array(32);
Deno.readSync(file.rid, data);
console.log(new TextDecoder().decode(data)); // Hello W

Parameters

rid: number
optional
len: number