Giter VIP home page Giter VIP logo

snappy.sharp's Introduction

Snappy.Sharp

An implementation of Google's Snappy compression algorithm in C#.

This is still a work in progress, especially the streaming stuff.

The current status is that I think the compression and expansion algorithms work right. The streaming stuff has only just been started and shouldn't even be used.

snappy.sharp's People

Contributors

andreassjoberg avatar jeffesp avatar shentuyuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

snappy.sharp's Issues

Compression creates even larger files

During my comparison of compression algorithms I've tested your nuget package (Snappy.Sharp 1.0.0), but something is wrong: compressing a 10MB binary file results in about 18MB output, which is quite the opposite of compression :-)

10478124 bytes => 18661217 bytes ~ 178,10%

Switching to another snappy binding (Snappy.Net if I remember correctly) results in a 64% compression ratio.

My code looks something like this:

FileInfo tmp = new FileInfo(Path.GetTempFileName());
using (FileStream fs = new FileStream(tmp.FullName, FileMode.Open, FileAccess.Write, FileShare.None))
using (SnappyStream s = new SnappyStream(fs, CompressionMode.Compress))
{
    // ... pump data into s

Exception in UnalignedCopy64

The following Code results in an Exception during decompression in Utilities.UnalignedCopy64:

byte[] uncompressed = new byte[100];
byte[] compressed = new byte[100];

Snappy.Sharp.SnappyCompressor snappyCompressor = new Snappy.Sharp.SnappyCompressor();
int countBytes = snappyCompressor.Compress( uncompressed, 0, 2, compressed, 0 );

Snappy.Sharp.SnappyDecompressor snappyDecompressor = new Snappy.Sharp.SnappyDecompressor();

// this call works
byte[] uncompressed2 = snappyDecompressor.Decompress( compressed, 0, countBytes );

// this call results in an Exception
snappyDecompressor.Decompress( compressed, 0, countBytes, uncompressed, 0, 100 );

The Exception occured with the Native-Implementation.

License, known issues

Hi,

Thanks for making this publicaly available and porting this to C#. I had some quick questions I hope you wouldn't mind answering.

First, I didn't see a license but wanted to check that if I ported this to another open source project for some uses under the apache license, that would be okay.

Second, the readme had a lot of caveats, but glancing through the code it seems to be 32/64 bit stable, and can't see why the runtime would make much difference. Do you have any particular reason to suspect problems or was the warning there just from an abundance of caution?

Thanks for any help,
N

Decompressed data not matching original data

The native implementation does sometimes not restore the original data when compressing and then decompressing.

      byte[] uncompressed   = new byte[] { 5,0,5,0,6,0,6,0,5,0,
                                                                5,0,5,0,5,0,5,0,6,0,
                                                                   6,0,5,0,5,0,5,0,5,0,
                                   5,0,5,0,5,0,5,0,5,0,
                                   5,0,5,0,4,0,5,0,5,0,
                                   5,0,5,0,5,0,4,0,5,0,
                                   5,0,5,0,5,0,5,0,4,0,
                                   5,0,5,0,5,0,5,0,5,0,
                                   5,0};
      byte[] compressed     = new byte[100];

      Snappy.Sharp.SnappyCompressor snappyCompressor = new Snappy.Sharp.SnappyCompressor();
      int countBytes = snappyCompressor.Compress( uncompressed, 0, uncompressed.Length, compressed, 0 );






      Snappy.Sharp.SnappyDecompressor snappyDecompressor = new Snappy.Sharp.SnappyDecompressor();

      byte[] uncompressed2 = snappyDecompressor.Decompress( compressed, 0, countBytes );

The last bytes are corrupted. The compression/decompression works fine for several similar data packages but after approx. 100 packages the above data produces corrupt data.

Compress() often returns wrong written length

We're seeing Compress return too-short lengths for the compressed data it has written.

This isn't an issue in the unit tests (apparently; I can't run them) because Decompress is happy to read longer than the compressedSize it has been passed. For more reliable testing, you should truncate the compressed buffer to the returned length before attempting to decompress the data:

var c = new Snappy.Sharp.SnappyCompressor();
var d = new Snappy.Sharp.SnappyDecompressor();    

var data = [ ... ]

var compressBuf = new byte[c.MaxCompressedLength(data.Length)];
var compressLen = c.Compress (data.Buffer, 0, data.Length, compressBuf);

// truncate the compressed buffer
compressBuf = compressBuf.Take (compressLen).ToArray ();

var decompressed = d.Decompress (compressBuf, 0, compressLen);
Assert.AreEqual (data, decompressed);

So I think there are two bugs here: Compress() doesn't return an accurate count of compressed bytes, and Decompress() continues to read beyond the compressLen it has been passed.

And it should be noted that this is with 7642fd8 applied, which was maybe an attempted fix for the same issue?

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.