Exemple #1
0
 public ZopfliStream(Stream inner, ZopfliFormat type, ZopfliOptions options, bool leaveOpen)
 {
     _innerStream   = inner;
     this.type      = type;
     this.options   = options;
     this.leaveOpen = leaveOpen;
 }
Exemple #2
0
        /// <summary>
        /// Internal convert method to convert byte array to compressed byte array
        /// </summary>
        /// <param name="data_in">Uncompressed data array</param>
        /// <param name="type">Format type, DEFLATE, GZIP, ZLIB</param>
        /// <param name="options">Compression options</param>
        /// <returns>Compressed data array</returns>
        public static byte[] compress(byte[] data_in, ZopfliFormat type, ZopfliOptions options)
        {
            IntPtr  result      = IntPtr.Zero;
            UIntPtr result_size = UIntPtr.Zero;

            try
            {
                // Get image data length
                UIntPtr data_size = (UIntPtr)data_in.Length;

                // Compress the data via native methods
                if (Environment.Is64BitProcess)
                {
                    ZopfliCompressor64.ZopfliCompress(ref options, type, data_in, data_in.Length, ref result, ref result_size);
                }
                else
                {
                    ZopfliCompressor32.ZopfliCompress(ref options, type, data_in, data_in.Length, ref result, ref result_size);
                }

                // Copy data back to managed memory and return
                return(NativeUtilities.GetDataFromUnmanagedMemory(result, (int)result_size));
            }
            catch
            {
                throw;
            }
            finally
            {
                // Free unmanaged memory
                Marshal.FreeHGlobal(result);
            }
        }
Exemple #3
0
 public ZopfliStream(Stream inner, ZopfliFormat type, bool leaveOpen)
 {
     _innerStream   = inner;
     this.type      = type;
     options        = new ZopfliOptions();
     this.leaveOpen = leaveOpen;
 }
Exemple #4
0
 public ZopfliStream(Stream inner, ZopfliFormat type, ZopfliOptions options)
 {
     _innerStream   = inner;
     this.type      = type;
     this.options   = options;
     this.leaveOpen = false;
 }
Exemple #5
0
 public ZopfliStream(Stream inner, ZopfliFormat type)
 {
     _innerStream   = inner;
     this.type      = type;
     options        = new ZopfliOptions();
     this.leaveOpen = false;
 }
Exemple #6
0
 public ZopfliStream(Stream inner)
 {
     _innerStream   = inner;
     type           = ZopfliFormat.ZOPFLI_FORMAT_DEFLATE;
     options        = new ZopfliOptions();
     this.leaveOpen = false;
 }
Exemple #7
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     if (!leaveOpen)
     {
         _innerStream.Dispose();
     }
     options = null;
 }
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     _innerStream.Dispose();
     options = null;
 }
 public ZopfliStream(Stream inner)
 {
     _innerStream = inner;
     type         = ZopfliFormat.ZOPFLI_FORMAT_DEFLATE;
     options      = new ZopfliOptions();
 }