private static void ZLib(Stream memoryStream, Peak1DArray peakArray) { using (var deflateStream = new DeflateStream(memoryStream, CompressionMode.Compress, true)) { NoCompression(deflateStream, peakArray); } }
private static void NoCompression(Stream memoryStream, Peak1DArray peakArray) { using (var writer = new BinaryWriter(memoryStream, Encoding.UTF8, true)) { foreach (var pk in peakArray.Peaks) { WriteValue(writer, peakArray.IntensityDataType, pk.Intensity); WriteValue(writer, peakArray.MzDataType, pk.Mz); } } }
private static void NoCompression(Stream stream, Peak1DArray peakArray) { using (var reader = new BinaryReader(stream, Encoding.UTF8, true)) { for (int i = 0; i < peakArray.ArrayLength; i++) { double intensity = ReadValue(reader, peakArray.IntensityDataType); double mz = ReadValue(reader, peakArray.MzDataType); peakArray.Peaks[i] = new Peak1D(intensity, mz); } } }
public void Decode(Stream stream, Peak1DArray peakArray) { switch (peakArray.CompressionType) { case BinaryDataCompressionType.NoCompression: NoCompression(stream, peakArray); break; case BinaryDataCompressionType.ZLib: ZLib(stream, peakArray); break; default: throw new NotSupportedException("Compression type not supported: " + peakArray.CompressionType.ToString()); } }
private static void NoCompression(Stream stream, Peak1DArray peakArray) { using (var reader = new BinaryReader(stream, Encoding.UTF8, true)) { int len = reader.ReadInt32(); Peak1D[] peaks = new Peak1D[len]; for (int i = 0; i < len; i++) { double intensity = ReadValue(reader, peakArray.IntensityDataType); double mz = ReadValue(reader, peakArray.MzDataType); peaks[i] = new Peak1D(intensity, mz); } peakArray.Peaks = peaks.ToMzLiteArray(); } }
public byte[] Encode(Peak1DArray peakArray) { memoryStream.Position = 0; switch (peakArray.CompressionType) { case BinaryDataCompressionType.NoCompression: NoCompression(memoryStream, peakArray); break; case BinaryDataCompressionType.ZLib: ZLib(memoryStream, peakArray); break; default: throw new NotSupportedException("Compression type not supported: " + peakArray.CompressionType.ToString()); } memoryStream.Position = 0; return(memoryStream.ToArray()); }