Atom

fs.truncate()

Sets a file's byte size.

Signature

fs.truncate(handle, length)

Parameters

Writable file and nonnegative signed byte length.

Returns

The requested length as i64.

Behavior

Changes file size and retains the cursor.

Errors

Read-only or closed file, invalid offset or OS failure.

Example

Atom
use fs
p = fs.temporary_file()
f = fs.open(p, 'w')
write(f, 'Atom')
assert(fs.truncate(f, 2) == 2)
fs.close(f)
assert(read(p) == 'At')
fs.remove(p)