public void SaveToStream(Stream Target) { var Header = new NoteDocumentHeader(); MemoryStream EncodedString; GZipStream Smallstring = null; byte[] CompressedBytes; try { Smallstring = new GZipStream(EncodedString = new MemoryStream(), CompressionLevel.Fastest); byte[] UncompressedBytes = Encoding.UTF8.GetBytes(CoreString); Smallstring.Write(UncompressedBytes, 0, UncompressedBytes.Length); } finally { Smallstring?.Dispose(); } CompressedBytes = EncodedString.GetBuffer(); Header.StringEncoding = EncodingData; Header.EncodingLength = CompressedBytes.Length; Header.WriteBytes(Target); Target.Write(CompressedBytes, 0, CompressedBytes.Length); }
/// <summary> /// make from this file. /// </summary> /// <param name="Source"></param> public NoteDocument(Stream Source) { var Header = new NoteDocumentHeader(Source); byte[] UncompressedBytes = new byte[Header.EncodingLength]; using (var ComressedStream = new GZipStream(Source, CompressionLevel.Fastest)) { ComressedStream.Read(UncompressedBytes, 0, Header.EncodingLength); } CoreString = Encoding.UTF8.GetString(UncompressedBytes); }