Problem with LZ4Stream

Feb 2, 2014 at 6:40 PM

I can't decompress my data with LZ4Stream the followed code :
                byte[] buffer;
                using (var stream = new FileStream(Path.Combine(_path, documentId + GetDocumentType(typeof (TDocument)).DocumentExtension()),FileMode.Open, FileAccess.Read, FileShare.None))
                    using (var lzStream = new LZ4.LZ4Stream(stream, CompressionMode.Decompress, true))
                        buffer = new byte[lzStream.Length];
                        lzStream.Read(buffer, 0, (int) lzStream.Length);
Failed because lzStream.Length always equals -1

Compression work well .

Thanks you for your help
Feb 3, 2014 at 1:06 PM
It's -1 because it is not known. What you should do is to read until .Read returns 0 (this is the end of stream). That's what you do with streams of unknown length.