Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
19
Task/Truncate-a-file/Lasso/truncate-a-file.lasso
Normal file
19
Task/Truncate-a-file/Lasso/truncate-a-file.lasso
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
define file_truncate(path::string, size::integer) => {
|
||||
|
||||
local(file = file(#path))
|
||||
|
||||
fail_if(not(#file -> exists), -1, 'There is no file at the given path')
|
||||
fail_if(#file -> size < #size, -1, 'No point in truncating a file to a larger size than it already is')
|
||||
|
||||
#file -> setSize(#size)
|
||||
|
||||
}
|
||||
local(filepath = '//Library/WebServer/Documents/Lasso9cli/trunk/testing/lorem_ipsum_long.txt')
|
||||
|
||||
stdoutnl(file(#filepath) -> readbytes)
|
||||
stdoutnl('Original size: ' + file(#filepath) -> size)
|
||||
|
||||
file_truncate(#filepath, 300)
|
||||
|
||||
stdoutnl(file(#filepath) -> readbytes)
|
||||
stdout(file('Truncated size: ' + #filepath) -> size)
|
||||
28
Task/Truncate-a-file/Lingo/truncate-a-file-1.lingo
Normal file
28
Task/Truncate-a-file/Lingo/truncate-a-file-1.lingo
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
----------------------------------------
|
||||
-- Truncates file
|
||||
-- @param {string} filename
|
||||
-- @param {integer} length
|
||||
-- @return {bool} success
|
||||
----------------------------------------
|
||||
on truncate (filename, length)
|
||||
fp = xtra("fileIO").new()
|
||||
fp.openFile(filename, 0)
|
||||
if fp.status() then return false
|
||||
if fp.getLength()=length then
|
||||
-- nothing to do
|
||||
fp.closeFile()
|
||||
return true
|
||||
end if
|
||||
data = fp.readByteArray(length)
|
||||
if data.length<>length then
|
||||
fp.closeFile()
|
||||
return false
|
||||
end if
|
||||
fp.delete()
|
||||
fp.createFile(filename)
|
||||
fp.openFile(filename, 2)
|
||||
fp.writeByteArray(data)
|
||||
ok = fp.status()=0
|
||||
fp.closeFile()
|
||||
return ok
|
||||
end
|
||||
2
Task/Truncate-a-file/Lingo/truncate-a-file-2.lingo
Normal file
2
Task/Truncate-a-file/Lingo/truncate-a-file-2.lingo
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
-- truncates file to 10 KB length
|
||||
bx_file_truncate(_movie.path&"foo.dat", 10240)
|
||||
3
Task/Truncate-a-file/Nim/truncate-a-file.nim
Normal file
3
Task/Truncate-a-file/Nim/truncate-a-file.nim
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import posix
|
||||
|
||||
discard truncate("filename", 1024)
|
||||
5
Task/Truncate-a-file/Ring/truncate-a-file.ring
Normal file
5
Task/Truncate-a-file/Ring/truncate-a-file.ring
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
file = "C:\Ring\ReadMe.txt"
|
||||
fp = read(file)
|
||||
fpstr = left(fp, 100)
|
||||
see fpstr + nl
|
||||
write(file, fpstr)
|
||||
9
Task/Truncate-a-file/Sidef/truncate-a-file.sidef
Normal file
9
Task/Truncate-a-file/Sidef/truncate-a-file.sidef
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
func truncate(filename, len) {
|
||||
var file = File(filename);
|
||||
len > file.size ->
|
||||
&& die "The provided length is greater than the length of the file";
|
||||
file.truncate(len);
|
||||
}
|
||||
|
||||
# truncate "file.ext" to 1234 bytes
|
||||
truncate("file.ext", 1234);
|
||||
Loading…
Add table
Add a link
Reference in a new issue