60 posts
Posted 13 August 2018 - 12:41 PM
file = fs.open("/test.txt", "wb")
print(fs.getFreeSpace("/"))
file.write(23)
print(fs.getFreeSpace("/"))
file.write(90)
print(fs.getFreeSpace("/"))
file.write(54)
print(fs.getFreeSpace("/"))
file.close()
print(fs.getFreeSpace("/"))
the number remains the same even tho the avlable space should go down! (in my game anyway)
am i missunderstanding the use of fs.getFreeSpace ?
7083 posts
Location
Tasmania (AU)
Posted 13 August 2018 - 12:46 PM
When you request a write through a file handle, the data doesn't actually go to disk immediately - instead, it goes into a buffer. Typically the buffer contents are only written when you either flush or close the handle.
On top of that, files take up a minimum of 512 bytes.
60 posts
Posted 13 August 2018 - 12:58 PM
On top of that, files take up a minimum of 512 bytes.
ummm under testing of my video format i came all the up two 975KB's am i missunderstanding what you're saying?
7083 posts
Location
Tasmania (AU)
Posted 13 August 2018 - 01:28 PM
Sounds like you're reading "minimum" as "maximum". Files can certainly take up more than 512 bytes of storage, but they can't take up any less.
This means, for example, that if you have a 10 byte file (which consumes 512 bytes of storage), then adding another 20 bytes won't make any difference (because it'll still take up 512 bytes of storage). It's not until a file exceeds 512 bytes of content that it'll start to affect your free storage further.
60 posts
Posted 13 August 2018 - 02:07 PM
ahhhhh ok yeah makes sense
Sounds like you're reading "minimum" as "maximum".
yes i was
60 posts
Posted 13 August 2018 - 02:34 PM
great you're right makeing a for _ = 1, 600 do to one of the file.write functions makes a chance in the fs.getFreeSpace
any way of looking into a file handle and see how many bytes is in the buffer?
am getting a little issue:
Lfree = fs.getFreeSpace(path) --Last free space, path is pointing at a file
local function WB(num)
if Lfree < 14000 then
spaceE = true --space Error
peripheral.call("top", "playNote", 0,0) -- tryed to get a iron noteblock to make a sound when it gets too full
end
file.write(num)
end
--i added a
file.flush()
--at a place where it will be called evrey 2000 bytes should be well before it hits zero
the spaceE never gets set to true
and no sound is ever played
7083 posts
Location
Tasmania (AU)
Posted 13 August 2018 - 03:26 PM
any way of looking into a file handle and see how many bytes is in the buffer?
Not really. You can assume it's empty after flushing, though.
am getting a little issue:
the spaceE never gets set to true
and no sound is ever played
Your code only ever checks the available free space once. If you want to check it multiple times, then you need to call fs.getFreeSpace() multiple times. The value recorded in Lfree isn't going to automatically update.
In cases where drive size is an issue, you might consider increasing it through
ComputerCraft.cfg - personally I've got it cranked up to the maximum, roughly a gig per computer.
If you're playing on a server and can't do that, then you may find
BBPack to be useful. Among other things, it can compress your whole filesystem, which typically allows for much more storage. To set this up, add os.loadAPI("bbpack") to the top of your startup file, then enter "bbpack compress" at the command line.
60 posts
Posted 13 August 2018 - 07:46 PM
Lfree = fs.getFreeSpace(path) --Last free space, path is pointing at a file << omfg am an ideot :D/>/>/>/>/>
local function WB(num)
if Lfree < 14000 then
spaceE = true --space Error
peripheral.call("top", "playNote", 0,0) -- tryed to get a iron noteblock to make a sound when it gets too full
end
file.write(num)
end
--i added a
file.flush()
--at a place where it will be called evrey 2000 bytes should be well before it hits zero
omfg am an ideot :D/> i didn't spot the fact that the Lspace is defined outside of the function :D/> i writen that line like 2am or some thing that maybe why
EDIT: with that said evreything is defined in a loop tho
Edited on 13 August 2018 - 05:48 PM