internal static MemoryStream CompressStream(Stream stream) { byte[] arr = new byte[stream.Length]; stream.Read(arr, 0, (int)stream.Length); MemoryStream ms = new MemoryStream(); BZip2Stream bzip = new BZip2Stream(ms, CompressionMode.Compress, true, false); bzip.Write(arr, 0, arr.Length); bzip.Close(); return(ms); }
/// <summary> /// Saves this chunk to the specified stream. /// </summary> /// <param name="destination">The destination stream to save the chunk to.</param> public async Task SaveTo(Stream destination) { BZip2Stream compressor = new BZip2Stream(destination, CompressionMode.Compress, true); StreamWriter destWriter = new StreamWriter(compressor) { AutoFlush = true }; await destWriter.WriteLineAsync(JsonConvert.SerializeObject(this)); compressor.Close(); destination.Close(); }