Jump to content




CCA - Compressed Computercraft Archive Library

api utility

9 replies to this topic

#1 minizbot2012

  • Members
  • 122 posts
  • LocationPalm Bay, Florida

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

Edited by minizbot2012, 01 May 2016 - 12:51 AM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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.

#3 minizbot2012

  • Members
  • 122 posts
  • LocationPalm Bay, Florida

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.co...ormats/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)

#4 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

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.)

#5 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 10 March 2016 - 05:37 PM

View PostCreator, on 10 March 2016 - 04:36 PM, said:

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 by SquidDev, 10 March 2016 - 05:39 PM.


#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 11 March 2016 - 01:01 AM

My main problem with the ZIP libraries Grin uses is that they're dead slow.

#7 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 11 March 2016 - 08:50 AM

View PostBomb Bloke, on 11 March 2016 - 01:01 AM, said:

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 :(.

#8 minizbot2012

  • Members
  • 122 posts
  • LocationPalm Bay, Florida

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.

#9 CrazedProgrammer

  • Members
  • 495 posts
  • LocationWageningen, The Netherlands

Posted 25 March 2016 - 06:46 PM

Little Endian is the best Endian :)

#10 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 31 July 2016 - 08:25 PM

I used CCA for compression in PROGDOR. Thanks!

EDIT: And now I put it in Progdor 2.0. Thanks again

Edited by LDDestroier, 27 January 2019 - 04:26 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users