This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Cross_Sans's profile picture

FLCF - Fast Lightweight Compressed File

Started by Cross_Sans, 25 January 2017 - 02:05 PM
Cross_Sans #1
Posted 25 January 2017 - 03:05 PM
FLCF - Fast Lightweight Compressed File


Hello !

Today, I created a lightweight API called FLCF which will helps you to compress files.

Download it here:
http://pastebin.com/2rYQaQef
or with the CraftOS shell:
pastebin get 2rYQaQef FLCF

It's really simple to use it:

os.loadAPI("FLCF"); – Loads our API
FLCF.createArchive("/myArchive.flcf"); – Create the archive at the root directory.
uarch = FLCF.openArchive("/myArchive.flcf"); – Opens the archive newly created.
uarch.addFile("/rom/programs/edit", "/edit"); – Adds the file edit from /rom/programs to the root directory of the archive.
uarch.saveArchive(); – Save our edited archive.
uarch.extractFile("/edit", "/a_editor"); – Extracts the file edit from the root directory of the archive.
uarch.removeFile("/edit"); – Removes the file edit from the root directory of the archive.
uarch.saveArchive(); – Save our edited archive.


That is it. Note that if you want to add multiple files from a directory, use this code:
os.loadAPI("FLCF");
FLCF.createArchive("/myArchive.flcf");
uarch = FLCF.openArchive("/myArchive.flcf");

for _, file in ipairs(fs.list("/photos")) do
if fs.isDir("/photos/" .. file) then
uarch.addFile("/photos" .. file, file);
end
end

uarch.saveArchive();

License:
Because of a outdated project stolen by Anonymous (click there to see the topic) without any permission (and also my fault because I did not put a license), this API is under MIT license (click here for license details). You can freely edit, modify, share with your friends this program; but do not forget to take credit to me if you are going to use this in a program or a operating system.

Thanks for reading my little post. I hope that you will find it useful. Please take some time to write your impressions and what needs to be added.

Have a nice day, Redall.
Edited on 25 January 2017 - 02:10 PM
Bomb Bloke #2
Posted 27 January 2017 - 01:05 AM
Er um I don't see the part where it compresses anything?
Anavrins #3
Posted 27 January 2017 - 02:13 AM
Er um I don't see the part where it compresses anything?
My thoughts exactly.
It looks more like something similar to a .tar file type of archiving, but there's also the fact you use the original serialize function which adds a lot of unnecessary newline and spaces, that will infact make the file much bigger than it should be, quite the opposite of compression.
Otherwise, the API looks neat and easy to use :)/>
Edited on 27 January 2017 - 01:14 AM
Cross_Sans #4
Posted 27 January 2017 - 11:21 AM
Er um I don't see the part where it compresses anything?

Yes, it not compress the data, but the files into a single file. But I plan to compress data when more people will be interested in this. And yes, I use textutils.serialise, but I will change that soon too. I was bored, so I created this API.
Edited on 27 January 2017 - 10:24 AM