/// <summary> /// 解压缩数据 /// </summary> /// <param name="compressData">压缩数据</param> /// <param name="type">压缩类型</param> /// <param name="startIndex">起始位置</param> /// <param name="count">解压缩字节数</param> /// <returns>解压缩后的数据</returns> public static byte[] getDeCompress(this byte[] compressData, compression type, int startIndex, int count) { using (memoryStream stream = compressData.getDeCompressStream(type, startIndex, count)) { return(stream != null?stream.ToArray() : nullValue <byte> .Array); } }
/// <summary> /// 解压缩数据 /// </summary> /// <param name="compressData">压缩数据</param> /// <param name="type">压缩类型</param> /// <param name="startIndex">起始位置</param> /// <param name="count">解压缩字节数</param> /// <returns>解压缩后的数据</returns> public static memoryStream getDeCompressStream(this byte[] compressData, compression type, int startIndex, int count) { array.range range = new array.range(compressData.length(), startIndex, count); if (count == range.GetCount) { using (Stream memoryStream = new MemoryStream(compressData, 0, compressData.Length)) using (Stream compressStream = memoryStream.toCompressStream(CompressionMode.Decompress, false, type)) { memoryStream dataStream = new memoryStream(compressData.Length); byte[] buffer = new byte[config.pub.Default.StreamBufferLength]; for (int readLength = compressStream.Read(buffer, 0, config.pub.Default.StreamBufferLength); readLength != 0; readLength = compressStream.Read(buffer, 0, config.pub.Default.StreamBufferLength)) { dataStream.Write(buffer, 0, readLength); } return(dataStream); } } else if (count == 0) { return(null); } log.Default.Throw(log.exceptionType.IndexOutOfRange); return(null); }
/// <summary> /// 写数据 /// </summary> /// <param name="stream">数据</param> public void Write(memoryStream stream) { if (stream != null) { prepLength(stream.Length); Buffer.BlockCopy(stream.array, 0, array, Length, stream.Length); Length += stream.Length; } }
public void UnsafeWrite(memoryStream stream) { Buffer.BlockCopy(stream.array, 0, array, Length, stream.Length); Length += stream.Length; }
/// <summary> /// 写数据 /// </summary> /// <param name="stream">数据,不能为null</param> public void Write(memoryStream stream) { Buffer.BlockCopy(stream.array, 0, Stream.array, Stream.Length, stream.Length); Stream.Length += stream.Length; }