jaime-olivares / zipstorer

A Pure C# Class to Store Files in Zip
MIT License
183 stars 63 forks source link

hello , i want to zip to memorystream #12

Closed ymh199478 closed 7 years ago

ymh199478 commented 7 years ago

hello , i want save to MemoryStream , export the file by external code . but found that the export of the file can not be properly extracted.

        public byte[] Compress(byte[] bytes)
        {
            Stream stream = new MemoryStream();

            ZipStorer zip = ZipStorer.Create(stream, string.Empty);

            Stream zipData = new MemoryStream(bytes);
            zip.AddStream(ZipStorer.Compression.Deflate ,"default", zipData, DateTime.Now, string.Empty);

            bytes = zip.Close(); // i change this code, make it can return byte[]
            return bytes;
        }
jaime-olivares commented 7 years ago

Close() should not return a byte array. It is not like that in any other API that handle streams. You should return stream.ToArray() instead.