Coder Social home page Coder Social logo

schallaven / pwexplode Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 3.0 69 KB

implementation of the PKWARE Data Compression Library format (imploding) for byte streams

License: GNU General Public License v3.0

Python 99.52% Shell 0.48%
pkware compression-algorithm

pwexplode's Introduction

pwexplode library

Simple implementation of the PKWARE Data Compression Library format (imploding) for byte streams in Python 3 licensed under GPL-3.0.

Implementation

This library is mostly based on the description of Ben Rudiak- Gould in the comp.compression group and zlib's blast.c.

It should be noted that there is a small mistake in Ben's example. He uses 00 04 82 24 25 c7 80 7f as example, which should decompress to AIAIAIAIAIAIA. However, testing this with my implementation failed. When I created it with the official pkware ziptool (see tests in pwexplode), the sequence turned out to be actually 00 04 82 24 25 8f 80 7f (notice the difference at byte 6). This will successfully decompress to AIAIAIAIAIAIA.

Instead of pure dictionaries, this package uses functions to provide the data of the tables necessary to decompress streams. This approach makes functions 'read-only' and can provide error feedback. However, it creates minimal overhead and slightly longer runtimes. In order to reduce the extra time a little bit, all tables are 'complete', i.e. each entry just needs to be extracted but not calculated. The difference is minimal and practical non-existant when accessing a function one time only; but these functions can be called hundred or thousand times per stream.

Usage

Import pwexplode in your Python 3 programs and call the explode(...) function. Note that input and output are byte strings!

import pwexplode
...
# Decompress input byte string 
inputdata = b'\x01\x04\x02\x6F\x5A\x08\xB6\x67\xE8\x86\x6A\xA9\x8A\x6D\x28'
            b'\x5E\x56\x6D\xCD\x5B\x5B\x6C\x47\x73\x18\xB6\x8A\x17\xF0\x0F'
...
outputdata = pwexplode.explode(inputdata) 
...
# prints b'I like consistent user interfaces.'
print(outputdata)

Calling pwexplode directly will run some tests:

$ ./pwexplode.py

Contributors

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.