Package: lz4tools
OverviewThis package consists of three parts:lz4f - C-Module containing python bindings for all lz4frame functions.lz4tools - a zipfile-like file wrapper class and tarfile-like class for lz4 compressed files.lz4toolsCli - a quick cli for using lz4tools static functions.Before going any further, I recommend reading up on lz4 at:https://code.google.com/p/lz4/It is an awesome compression algorithm and I can’t thank Yann Collet enough for
putting together the C implementation and lz4frame.Before going any further, I recommend reading up on lz4 at:https://code.google.com/p/lz4/It is an awesome compression algorithm and I can’t thank Yann Collet enough for putting together the C implementation and lz4frame.UsageCli:New addition, there is now a simple Cli for anyone wishing these
capabilities would exist directly on the command line.usage:lz4toolsCli[-h][-f][-t][-d][-i][-bs{4,5,6,7}][-bm{0,1}]input[output]positionalarguments:inputThetargetedinput.outputOptionaloutputtarget.optionalarguments:-h,--helpshowthishelpmessageandexit-fCompressfile.Defaultactionifinputisafile.-tCompressdirectoryto.tar.lz4.Defaultactionifinputisadirectory-dDecompressfile.Defaultactionifthefileendsin.lz4.-iPrintframeinformationfromthefile'sheader.-bs{4,5,6,7}SpecifyblkSizeId.Validvaluesare4-7.Defaultvalueis7.-bm{0,1}SpecifyblkMode.0=Chainedblocks.1=IndependentblocksDefaultvalueis0.C-Module / Bindings:I would recommend against using lz4f directly except in debug/testing
situations. If necessary, a compress or decompress operation first needs a
context that will be used with all lz4f functions:lz4f compression the hard way:>>>importlz4f>>>inputFile=open('fileIn','rb')>>>cCtx=lz4f.createCompressionContext>>>header=lz4f.compressBegin(cCtx)>>>data=lz4f.compressUpdate(inputFile.read(),cCtx)>>>end=lz4f.compressEnd(cCtx)>>>withopen('output.lz4','wb')asout:...out.write(header)...out.write(data)...out.write(end)...out.flush()...out.close()>>>lz4f.freeCompContext(cCtx)>>>inputFile.close()>>>delheader,data,endlz4f compression the easy way:>>>importlz4f>>>withopen('output.lz4','wb')asout:...withopen('fileIn','rb')asinFile:...out.write(lz4f.compressFrame(inFile.read())...out.flush()...out.close()Advantages and disadvantages:The easy way takes more ram. It reads the
contents of the file into a buffer, passes it and compresses it all in one
go. With the hard way you can have it read as little or as much as you
like. For instance, you can break up the input into 64kiB chunks.
Each chunk could be read, compressed and dropped to disk to conserve ram.Lz4Tools Module:The lz4file class is currently read only. Right now it is a bit rough around
the edges, however over the next couple of weeks, I will finish adding some
docstrings, and such to make it more user friendly. As soon as I get a chance
I will make it write capable. The easiest way to use it is with either the
open or openTar methods. That’s right! There is a lz4Tar class in the module
that is a subclass of tarfile.lz4tools tar example:>>>importlz4tools>>>lz4tools.compressTarDefault('src')>>>testTar=lz4tools.openTar('src.tar.lz4')>>>testTar.list()-rwxr-xr-xdarkdragn/darkdragn02014-10-0223:06:09src/-rw-r--r--darkdragn/darkdragn299052014-09-1618:29:45src/lz4hc.c-rw-r--r--darkdragn/darkdragn67812014-09-1618:29:45src/xxhash.h-rw-r--r--darkdragn/darkdragn256622014-09-1618:29:45src/xxhash.c-rw-rw-r--darkdragn/darkdragn138942014-10-0220:22:09src/lz4frame.h-rw-rw-r--darkdragn/darkdragn462412014-10-0220:22:09src/lz4.c-rw-r--r--darkdragn/darkdragn88322014-09-1618:29:45src/lz4hc.h-rw-rw-r--darkdragn/darkdragn117342014-10-0223:06:08src/python-lz4f.c-rw-rw-r--darkdragn/darkdragn25542014-10-0220:22:09src/python-lz4f.h-rw-r--r--darkdragn/darkdragn148822014-09-1801:28:06src/lz4.h-rw-rw-r--darkdragn/darkdragn501412014-10-0223:04:05src/lz4frame.clz4tools file example:>>>importlz4tools>>>lz4tools.compressFileDefault('setup.py')>>>testFile=lz4tools.open('setup.py.lz4')>>>testFile.blkDict{0:{'decomp_e':1445,'compressed_begin':7,'blkSize':923}}>>>testFile.seek(1002)>>>printtestFile.read()test_suite="nose.collector",keywords=['lz4','lz4frame','lz4file','lz4tar'],classifiers=['Development Status :: 5 - Production/Stable','License :: OSI Approved :: BSD License','Intended Audience :: Developers','Programming Language :: C','Programming Language :: Python','Programming Language :: Python :: 2.6','Programming Language :: Python :: 2.7',],)And thus ends the brief tutorial.NotesVersion:The first two digits of the version will always correspond with the version
of lz4 that is included. Current version is r123, thus 1.2. The next digit
corresponds to milestone improvements. Example: Once lz4file supports
write. The last digit will be slight improvements. Usually some contextual
error, or syntax error. Perhaps even a quick fix for python3.4, since I
don’t use it often, if an issue is brought to my attention, I will provide
a quick fix as quickly as possible.Version :The first two digits of the version will always correspond with the version of lz4 that is included. Current version is r124, thus 1.2. The next  digit is correspond to milestone improvements. Example: Once lz4file supports write. The last digit will be slight improvements. Usually some contextual error, or syntax error. Perhaps even a quick fix for python3.4, since I don’t use it often, if an issue is brought to my attention, I will provide a quick fix as quickly as possible.