Пример #1
0
        private Span <byte> DecompressNative(ReadOnlySpan <byte> src, int decompressBound)
        {
            fixed(byte *srcPtr = src)
            {
                var buffer = new byte[decompressBound];

                fixed(byte *decompressedBufferNativePtr = buffer)
                {
                    var dctx = ExternMethods.ZSTD_createDCtx();

                    try
                    {
                        var length = ExternMethods.ZSTD_decompressDCtx(dctx,
                                                                       (IntPtr)decompressedBufferNativePtr,
                                                                       (nuint)buffer.Length,
                                                                       (IntPtr)srcPtr, (nuint)src.Length);
                        return(new Span <byte>(buffer, 0, (int)length));
                    }
                    finally
                    {
                        ExternMethods.ZSTD_freeDCtx(dctx);
                    }
                }
            }
        }
Пример #2
0
 public void DecompressNative()
 {
     fixed(byte *dstPtr = dest)
     fixed(byte *uncompressedPtr = uncompressed)
     {
         ExternMethods.ZSTD_decompressDCtx(dCtxNative, (IntPtr)uncompressedPtr, (nuint)uncompressed.Length,
                                           (IntPtr)dstPtr, compressedLength);
     }
 }
Пример #3
0
        static unsafe void Test2()
        {
            var cctx = ExternMethods.ZSTD_createCCtx();
            var dctx = ExternMethods.ZSTD_createDCtx();

            var src          = File.ReadAllBytes("dickens");
            var dest         = new byte[ExternMethods.ZSTD_compressBound((nuint)src.Length)];
            var uncompressed = new byte[src.Length];

            fixed(byte *dstPtr = dest)
            fixed(byte *srcPtr          = src)
            fixed(byte *uncompressedPtr = uncompressed)
            {
                var compressedLength = ExternMethods.ZSTD_compressCCtx(cctx, (IntPtr)dstPtr, (nuint)dest.Length, (IntPtr)srcPtr, (nuint)src.Length,
                                                                       level);

                var decompressedLength = ExternMethods.ZSTD_decompressDCtx(dctx, (IntPtr)uncompressedPtr, (nuint)uncompressed.Length, (IntPtr)dstPtr, compressedLength);

                Console.WriteLine($"{compressedLength} {decompressedLength} {src.Length}");
            }
            ExternMethods.ZSTD_freeCCtx(cctx);
            ExternMethods.ZSTD_freeDCtx(dctx);
        }