ComputerCraft

ComputerCraft

21M Downloads

[Bug]Edit ignore space limit

JakobDev opened this issue ยท 2 comments

commented

As you will see from the attached gif, edit ignore the space limit.

space

commented

When ComputerCraft calculates the amount of space each file takes, it assumes a minimum file size of 500 bytes. This prevents people creating millions of empty files which, even though they are empty, would still take up some space on the physical disk. Consequently, there is no difference in "size" between an empty file, one with 200 characters in and one with 500 characters in.

That's what you're seeing here: the file you're testing with is less than 500 characters and so adding several more doesn't make any difference to the disk usage. If you go over 500 characters, then your file will be truncated.

TLDR: This isn't a bug, but a side effect of how CC calculates storage.


Just a couple of steps I used to double check the above. You'll either need to reach the limit, or et the computerSpaceLimit config option to 500.

-- Write an empty file
local a = fs.open("tmp.txt", "w")
a.close()
print(fs.getFreeSpace("/")) -- 0
print(fs.getSize("tmp.txt")) -- 0

-- Write a file with > 500 characters
local a = fs.open("tmp.txt", "w")
a.write(("x"):rep(501))
a.close()
print(fs.getFreeSpace("/")) -- 0
print(fs.getSize("tmp.txt")) -- 500

Note the last value isn't 501: reading the file will only give 500 xs.

commented

@SquidDev Thank you for explaining