Truncate a file: Difference between revisions

Content added Content deleted
(Lingo added)
Line 620: Line 620:


=={{header|Lingo}}==
=={{header|Lingo}}==
With native means (Fileio Xtra) file truncation can only be implemented indirectly, either using a temp file or loading truncated file contents into memory, deleting original and writing memory back to file.
With native means (Fileio Xtra) file truncation can only be implemented indirectly, either using a temp file or loading truncated file contents into memory, deleting original and writing memory back to file:
<lang lingo>----------------------------------------

-- Truncates file
But there are free plugins ("Xtras") like e.g. "BinFile Xtra" that support "in-file" truncation:
-- @param {string} filename
-- @param {integer} length
-- @return {bool}
----------------------------------------
on truncate (filename, length)
fp = xtra("fileIO").new()
fp.openFile(filename, 0)
data = fp.readByteArray(length)
fp.delete()
fp.createFile(filename)
fp.openFile(filename, 2)
fp.writeByteArray(data)
err = fp.status()
fp.closeFile()
fp=0
return (err=0)
end</lang>
But there are also free plugins ("Xtras") like e.g. "BinFile Xtra" that support "in-file" truncation:
{{libheader|BinFile Xtra}}
{{libheader|BinFile Xtra}}
<lang lingo>-- truncates file to 10 KB length
<lang lingo>-- truncates file to 10 KB length