// Token: 0x06000013 RID: 19 RVA: 0x00002270 File Offset: 0x00000470 public int Wrap(ArraySegment <byte> src, byte[] dst, int offset) { if (offset < 0 || offset >= dst.Length) { throw new ArgumentOutOfRangeException("offset"); } if (src.Count == 0) { return(0); } int num = dst.Length - offset; UIntPtr uintPtr; using (ArraySegmentPtr arraySegmentPtr = new ArraySegmentPtr(src)) { using (ArraySegmentPtr arraySegmentPtr2 = new ArraySegmentPtr(new ArraySegment <byte>(dst, offset, num))) { if (this.Options.Cdict == IntPtr.Zero) { uintPtr = ExternMethods.ZSTD_compressCCtx(this.cctx, arraySegmentPtr2, (UIntPtr)((ulong)((long)num)), arraySegmentPtr, (UIntPtr)((ulong)((long)src.Count)), this.Options.CompressionLevel); } else { uintPtr = ExternMethods.ZSTD_compress_usingCDict(this.cctx, arraySegmentPtr2, (UIntPtr)((ulong)((long)num)), arraySegmentPtr, (UIntPtr)((ulong)((long)src.Count)), this.Options.Cdict); } } } uintPtr.EnsureZstdSuccess(); return((int)((uint)uintPtr)); }
public int Wrap(ArraySegment <byte> src, byte[] dst, int offset) { if (offset < 0 || offset >= dst.Length) { throw new ArgumentOutOfRangeException("offset"); } if (src.Count == 0) { return(0); } var dstCapacity = dst.Length - offset; size_t dstSize; using (var srcPtr = new ArraySegmentPtr(src)) using (var dstPtr = new ArraySegmentPtr(new ArraySegment <byte>(dst, offset, dstCapacity))) { if (Options.Cdict == IntPtr.Zero) { dstSize = ExternMethods.ZSTD_compressCCtx(cctx, dstPtr, (size_t)dstCapacity, srcPtr, (size_t)src.Count, Options.CompressionLevel); } else { dstSize = ExternMethods.ZSTD_compress_usingCDict(cctx, dstPtr, (size_t)dstCapacity, srcPtr, (size_t)src.Count, Options.Cdict); } } dstSize.EnsureZstdSuccess(); return((int)dstSize); }
// Token: 0x06000020 RID: 32 RVA: 0x00002564 File Offset: 0x00000764 public static ulong GetDecompressedSize(ArraySegment <byte> src) { ulong result; using (ArraySegmentPtr arraySegmentPtr = new ArraySegmentPtr(src)) { result = ExternMethods.ZSTD_getDecompressedSize(arraySegmentPtr, (UIntPtr)((ulong)((long)src.Count))); } return(result); }
public DecompressorStream(Stream stream, DecompressionOptions options) { InnerStream = stream; Options = options; DStream = ZSTD_createDStream(); if (options == null || options.Ddict == IntPtr.Zero) { ZSTD_initDStream(DStream); } else { ZSTD_initDStream_usingDDict(DStream, options.Ddict); } InputBuffer = CreateInputBuffer(); InitializeInputBufferState(); }
public override void Write(byte[] buffer, int offset, int count) { using (var inBuffer = new ArraySegmentPtr(buffer, offset, count)) { var inputBufferState = new ZSTD_Buffer(inBuffer); while (!inputBufferState.IsFullyConsumed) { if (OutputBufferState.IsFullyConsumed) { FlushOutputBuffer(); } ZSTD_compressStream(CStream, ref OutputBufferState, ref inputBufferState).EnsureZstdSuccess(); } } }
public CompressorStream(Stream stream, CompressionOptions options) { InnerStream = stream; Options = options; CStream = ZSTD_createCStream(); if (options.Cdict == IntPtr.Zero) { ZSTD_initCStream(CStream, options.CompressionLevel).EnsureZstdSuccess(); } else { ZSTD_initCStream_usingCDict(CStream, options.Cdict).EnsureZstdSuccess(); } OutputBuffer = CreateOutputBuffer(); InitializedOutputBufferState(); }
public override int Read(byte[] buffer, int offset, int count) { using (var outputBufferPtr = new ArraySegmentPtr(buffer, offset, count)) { var outputBufferState = new ZSTD_Buffer(outputBufferPtr); while (!outputBufferState.IsFullyConsumed) { if (InputBufferState.IsFullyConsumed && !TryRefreshInputBuffer()) { break; } ZSTD_decompressStream(DStream, ref outputBufferState, ref InputBufferState).EnsureZstdSuccess(); } return(outputBufferState.IntPos - offset);//return change in output position as number of read bytes } }
public int Unwrap(ArraySegment <byte> src, byte[] dst, int offset, bool bufferSizePrecheck = true) { if (offset < 0 || offset >= dst.Length) { throw new ArgumentOutOfRangeException(nameof(offset)); } if (src.Count == 0) { return(0); } var dstCapacity = dst.Length - offset; using (var srcPtr = new ArraySegmentPtr(src)) { if (bufferSizePrecheck) { var expectedDstSize = ExternMethods.ZSTD_getDecompressedSize(srcPtr, (size_t)src.Count); if ((int)expectedDstSize > dstCapacity) { throw new InsufficientMemoryException("Buffer size is less than specified decompressed data size"); } } size_t dstSize; using (var dstPtr = new ArraySegmentPtr(new ArraySegment <byte>(dst, offset, dstCapacity))) { if (Options.Ddict == IntPtr.Zero) { dstSize = ExternMethods.ZSTD_decompressDCtx(dctx, dstPtr, (size_t)dstCapacity, srcPtr, (size_t)src.Count); } else { dstSize = ExternMethods.ZSTD_decompress_usingDDict(dctx, dstPtr, (size_t)dstCapacity, srcPtr, (size_t)src.Count, Options.Ddict); } } dstSize.EnsureZstdSuccess(); return((int)dstSize); } }
// Token: 0x06000022 RID: 34 RVA: 0x000025C4 File Offset: 0x000007C4 public int Unwrap(ArraySegment <byte> src, byte[] dst, int offset, bool bufferSizePrecheck = true) { if (offset < 0 || offset >= dst.Length) { throw new ArgumentOutOfRangeException("offset"); } if (src.Count == 0) { return(0); } int num = dst.Length - offset; int result; using (ArraySegmentPtr arraySegmentPtr = new ArraySegmentPtr(src)) { if (bufferSizePrecheck && (int)ExternMethods.ZSTD_getDecompressedSize(arraySegmentPtr, (UIntPtr)((ulong)((long)src.Count))) > num) { throw new InsufficientMemoryException("Buffer size is less than specified decompressed data size"); } UIntPtr uintPtr; using (ArraySegmentPtr arraySegmentPtr2 = new ArraySegmentPtr(new ArraySegment <byte>(dst, offset, num))) { if (this.Options.Ddict == IntPtr.Zero) { uintPtr = ExternMethods.ZSTD_decompressDCtx(this.dctx, arraySegmentPtr2, (UIntPtr)((ulong)((long)num)), arraySegmentPtr, (UIntPtr)((ulong)((long)src.Count))); } else { uintPtr = ExternMethods.ZSTD_decompress_usingDDict(this.dctx, arraySegmentPtr2, (UIntPtr)((ulong)((long)num)), arraySegmentPtr, (UIntPtr)((ulong)((long)src.Count)), this.Options.Ddict); } } uintPtr.EnsureZstdSuccess(); result = (int)((uint)uintPtr); } return(result); }
public ZSTD_Buffer(ArraySegmentPtr segmentPtr) { buffer = segmentPtr; size = (size_t)segmentPtr.Length; pos = default(size_t); }
public static ulong GetDecompressedSize(ArraySegment <byte> src) { using (var srcPtr = new ArraySegmentPtr(src)) return(ExternMethods.ZSTD_getDecompressedSize(srcPtr, (size_t)src.Count)); }