problems with DLL ?


Hi! Great job you performed there; congratulations.

But I'm having some issues here in VS2010. I can't decode data compressed by Lz4-for-NET.

Since I don't know really the size of UNCOMPRESSED OUTPUT (I'm handling with 4 to 8 Mb of random data), it should allow me to decode data wihout that information.

And I have a little test here using the following code. I noticed that:
1- Encode and EncodeHC created the SAME data output, in size and contents.
2- I can't decode it.

See code:

Dim cave As Byte() = Encoding.ASCII.GetBytes("akhjkahwy98skhssbsy9ydddddddddddddddddddddddddddd9879roefhdohoffhsd08wyfy0y0y0fsdfhdoshssodhossssssssssssssssss0980w98r0uepewjfejdjefd0pe90c8[0280238v[089rv0[8g09rbv90[8r908r[v8g98vbeb8fub0vu0[r7[027g[ v97g3907g90r7v7vg03r7vg309720[9v7g0[r927g0397g[0")
    Matriz2 = LZ4.LZ4Codec.EncodeHC(cave, 0, cave.Length)
'--- Above was 100%. Using VS2010, mixed mode, output = MixedMode 64/MixedMode 64/MixedMode 64HC
    matriz3 = LZ4.LZ4Codec.Encode(cave, 0, cave.Length)
'--- Above was 100%. Using VS2010, mixed mode, output = MixedMode 64/MixedMode 64/MixedMode 64HC <<< but I don't called HC !! I called ENCODE alone...
    Dim tamanho As Integer = matriz3.Length
    Dim teste As String = Encoding.ASCII.GetString(LZ4.LZ4Codec.Decode(matriz3, 0, tamanho, 1))
OPS!! ERROR. Since I defined as 1 (or even 0) the function throws an exception. But in THIS case I know the size of the output, but in the real life I won't know.

Kind regards,
Closed Sep 19, 2014 at 11:33 AM by Krashan


Krashan wrote Sep 8, 2014 at 9:40 PM

I'm not sure if I understand it right.
You are not saying there is a bug, you just request new feature, right?
You are not saying that you provide right output length but it crashes, you are saying that you don't want to provide output length, and LZ4 should guess it automatically?

Am I right?

caverna2012 wrote Sep 8, 2014 at 10:08 PM

Hi Krasham,

Yes, I don't see it as a bug, but how can I know the uncompressed length of a received compressed data?
Let's suppose I receive a STRING or BYTE data from someone. To uncompress it I must define a kind of buffer for this (the third parameter of the uncompress function). But how can estimate the correct size for it?

I had compressed both BYTE and STRING data but to uncompress them I need to inform the size of the destination buffer - or in other words, its UNCOMPRESSED length, right? I suppose its not correct...

I tried the values of 1, 0 and empty parameter and in all of them I received an error from function.
My problem is NOT to allocate megabytes of buffer to do it, but:

1- The buffer size may vary from data to data (eg. 120kb or 12Mb compressed data)
2- I don't know the rate of compression efectively done, so, I need ONLY to estimate a buffer size - and this may cause error if underestimated.

Thanks for your prompt answer.
Kind regards!

Krashan wrote Sep 10, 2014 at 10:21 AM

So this is not the "problem with DLL" it is just how it works. You do need to provide proper output length.
You can workaround this issue by using: LZ4Codec.Wrap/LZ4Codec.Unwrap or LZ4Stream. Both ways storing length is handled for you.

caverna2012 wrote Sep 10, 2014 at 8:43 PM

Hmmm..... I understood. Thanks for your reply, I will make some tests later.
Kind regards Krashan.