Esempio n. 1
0
    unsafe MemoryStream zstdPackFancy(byte[] input)
    {
        var cbuf = new byte[(int)ZSTD.ZSTD_compressBound((IntPtr)input.Length)];
        var ctx  = ZSTD.ZSTD_createCCtx();
        var dpos = (IntPtr)0;
        var spos = (IntPtr)0;

        ZSTD.ZSTD_CCtx_setParameter(ctx, (IntPtr)100, 999);

        ZSTD.ZSTD_CCtx_setParameter(ctx, (IntPtr)101, 24);   //window
        ZSTD.ZSTD_CCtx_setParameter(ctx, (IntPtr)103, 24);   // chainlog
        ZSTD.ZSTD_CCtx_setParameter(ctx, (IntPtr)104, 24);   //searchlog
        ZSTD.ZSTD_CCtx_setParameter(ctx, (IntPtr)105, 2);    //minma

        ZSTD.ZSTD_CCtx_setParameter(ctx, (IntPtr)106, 9999); //tlen
        ZSTD.ZSTD_CCtx_setParameter(ctx, (IntPtr)107, 9);
        ZSTD.ZSTD_CCtx_setParameter(ctx, (IntPtr)402, 9);
        ZSTD.ZSTD_CCtx_setParameter(ctx, (IntPtr)400, 8);


        fixed(byte *pcbuf = cbuf)
        {
            ZSTD.ZSTD_compress_generic_simpleArgs(ctx, new IntPtr(pcbuf), (IntPtr)cbuf.Length, out dpos, input, (IntPtr)input.Length, out spos, (IntPtr)22);
        }

        ZSTD.ZSTD_freeCCtx(ctx);
        var res = new MemoryStream();

        res.Write(cbuf, 0, (int)dpos);
        return(res);
    }
        public static byte[] CompressFile(byte[] data, IFileFormat format)
        {
            int Alignment = 0;

            if (format.IFileInfo != null)
            {
                Alignment = format.IFileInfo.Alignment;
            }

            switch (format.IFileInfo.CompressionType)
            {
            case CompressionType.Yaz0:
                return(EveryFileExplorer.YAZ0.Compress(data, 3, (uint)Alignment));

            case CompressionType.Zstb:
                return(ZSTD.Compress(data));

            case CompressionType.Zlib:
                return(ZLIB.Compress(data));

            case CompressionType.None:
                return(data);

            default:
                return(data);
            }
        }
Esempio n. 3
0
    unsafe MemoryStream zstdPack(byte[] input)
    {
        var cbuf = new byte[(int)ZSTD.ZSTD_compressBound((IntPtr)input.Length)];
        int clen;

        fixed(byte *pcbuf = cbuf)
        {
            clen = (int)ZSTD.ZSTD_compress(new IntPtr(pcbuf), (IntPtr)cbuf.Length, input, (IntPtr)input.Length, 22);
        }

        var res = new MemoryStream();

        res.Write(cbuf, 0, clen);
        return(res);
    }