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

CCA - Compressed Computercraft Archive Library

Started by minizbot2012, 08 March 2016 - 01:11 AM
minizbot2012 #1
Posted 08 March 2016 - 02:11 AM
CCA - Compressed Computercraft Archive

This API presents several interesting interfaces, including an archive format that supports folders and compressed files.

to get an archiver instance:
archiver = cca.newArchiver()
to compress a folder with the archiver call:
archiver:compress(outputfilename, foldertocompressname)
to decompress the archive call
archiver:decompress(archiveFileName, folderToDecompressTo)
Some of the other methods that are less useful include file operations that allow:
* reading and writing bytes
* reading and writing an array of bytes
* reading and writing a string into a binary file
* reading and writing basic data types such as integers, and shorts
and finally you get 2 functions these are for using the lzw compressor directly
* compress used for compressing a string lzw.compress(string)
* decompress used for decompressing an array of compressed bytes lzw.decompress(compressedByteArray)

notes about the lzw compressor:
* Supports the clear code (256 internally)
* able to be written directly to a file with the write bytes given a binary file handle ('wb')
notes about reading and writing binary file functions:
* all take a file handle as first argument
* writing commands

writeByte(fh, byte)
writeShort(fh, short)
writeInt(fh, int)
writeString(fh, string)
writeBytes(fh, byteArray)
* reading commands (all return respective datatypes)

readByte(fh)
readShort(fh)
readInt(fh)
readString(fh)
readBytes(fh)
LINK: http://pastebin.com/xJPwMHjX
Pastebin ID: xJPwMHjX
closing notes:
The full spec of the archive format is included in lines 185 - 205 so find those lines if you want to know a bit more :)/>
Do whatever you want with it :)/> I could care-less if you used this or not, but if you do use this definitely let me know (if you want to)

Changelog
3/25/16Changed to little endian (mostly) WARNING: This is a breaking change (all ccas will be broken)
Removed local modifiers for several parts of the CCA archive API (mostly for extensions for it)
No LZH format yet (still working on it)
Edited on 30 April 2016 - 11:51 PM
Bomb Bloke #2
Posted 10 March 2016 - 10:32 AM
Gave it a quick test and it seems to work well enough, so good job: there aren't many working compressors for ComputerCraft. :)/>

I'm not sure I understand the point of the OOP stuff, though? What's the purpose of generating a new archiver object after loading the API?

A suggestion, if you're interested: the LZH file format makes use of LZW. You could rig your compressor to make archives that work directly with 7zip, WinRAR, etc.
minizbot2012 #3
Posted 10 March 2016 - 03:06 PM
After looking at the format, I think I can do it, (resource that I've found, if you have a better one, please tell me: http://www.onicos.com/staff/iz/formats/lzh.html )
As for the OOP, I was tired but, IIRC it made it easier for me to handle the current archiver's folder-system (due to the decompressor being stack-based)
Creator #4
Posted 10 March 2016 - 04:36 PM
Would this mean that we can decompress real Zip files in CC? That would be awesome.

Also, sorry for taking the name Compress. (It is a mere archiver.)
SquidDev #5
Posted 10 March 2016 - 05:37 PM
Would this mean that we can decompress real Zip files in CC? That would be awesome.
Grin can decompress them but downloading zip files is near-impossible as they are binary files. Compression would be pretty awesome, but I think it uses deflate/inflate rather than LZW. Deflate might be another one you could tackle, but I think it is a much more complex.
Edited on 10 March 2016 - 04:39 PM
Bomb Bloke #6
Posted 11 March 2016 - 01:01 AM
My main problem with the ZIP libraries Grin uses is that they're dead slow.
SquidDev #7
Posted 11 March 2016 - 08:50 AM
My main problem with the ZIP libraries Grin uses is that they're dead slow.
It doesn't use the bit library. I'm not sure why, but using it would increase the performance a lot. Any number-crunching in CC isn't especially fast :(/>.
minizbot2012 #8
Posted 25 March 2016 - 04:07 PM
Made a major change in the binary format, changed to little endian this will break all compressed archives created with this API, this is in preparation for LZH (soon™) Please uncompress any saved data, update the API then recompress.
CrazedProgrammer #9
Posted 25 March 2016 - 06:46 PM
Little Endian is the best Endian :)/>
LDDestroier #10
Posted 31 July 2016 - 09:25 PM
I used CCA for compression in PROGDOR. Thanks!

EDIT: And now I put it in Progdor 2.0. Thanks again
Edited on 27 January 2019 - 03:26 AM