Exemplo n.º 1
0
    public static void SaveAsGzipFile(System.IO.Stream s, string content)
    {
        byte[] data    = System.Text.Encoding.UTF8.GetBytes(content);
        byte[] deflate = Deflator.DeflateToByteArray(data, 9);

        s.WriteByte(31);  // ID1
        s.WriteByte(139); // ID2
        s.WriteByte(8);   // CM  deflate
        s.WriteByte(1);   // text file

        long mtime = (long)(System.DateTime.Now - UNIX_EPOCH).TotalSeconds;

        s.WriteByte((byte)(0xFF & mtime));
        s.WriteByte((byte)(0xFF & mtime >> 8));
        s.WriteByte((byte)(0xFF & mtime >> 16));
        s.WriteByte((byte)(0xFF & mtime >> 24));

        s.WriteByte(2); // highest compression
        s.WriteByte(3); // line break = unix style '\n'

        s.Write(deflate, 0, deflate.Length);

        uint crc32 = Deflator.CalculateCrc32(data);

        s.WriteByte((byte)(0xFF & crc32));
        s.WriteByte((byte)(0xFF & crc32 >> 8));
        s.WriteByte((byte)(0xFF & crc32 >> 16));
        s.WriteByte((byte)(0xFF & crc32 >> 24));
        uint isize = (uint)data.Length;

        s.WriteByte((byte)(0xFF & isize));
        s.WriteByte((byte)(0xFF & isize >> 8));
        s.WriteByte((byte)(0xFF & isize >> 16));
        s.WriteByte((byte)(0xFF & isize >> 24));
    }
Exemplo n.º 2
0
        // Compression functions

        public int PutStream(byte [] data)
        {
            int result = StartObj();

            Put("<<");
            if (Compress)
            {
                Put("/Filter/FlateDecode");
      #if ( UseZLib )
                {
                    data = Deflate(data);
                    Put("/Length " + data.Length + ">>stream\n");
                    Put(data);
                }
      #else
                {
                    MemoryBitStream bb = new MemoryBitStream();
                    Deflator.Deflate(data, bb);
                    int clen = bb.ByteSize();
                    Put("/Length " + clen + ">>stream\n");
                    bb.CopyTo(OS);
                    OS_Total += clen;
                }
      #endif
            }
            else
            {
                Put("/Length " + data.Length + ">>stream\n");
                Put(data);
            }
            Put("\nendstream");
            EndObj();
            return(result);
        }
Exemplo n.º 3
0
     public static byte [] Deflate(byte [] data)
     {
 #if ( UseZLib )
         IO.MemoryStream            cs  = new IO.MemoryStream();
         Zlib.ZDeflaterOutputStream zip = new Zlib.ZDeflaterOutputStream(cs);
         zip.Write(data, 0, data.Length);
         zip.Finish();
         return(cs.ToArray());
 #else
         MemoryBitStream mbs = new MemoryBitStream();
         Deflator.Deflate(data, mbs);
         return(mbs.ToArray());
 #endif
     }
Exemplo n.º 4
0
    public static string CreateSfx85(string input)
    {
        // prepare resource
        System.IO.Stream sFrame = getManifestResource("sfxframe85.js");
        if (sFrame == null)
        {
            return(input);
        }

        // source
        string compressed = Deflator.DeflateToJ85String(input, 9);

        // inflate
        System.IO.StreamReader sr = new System.IO.StreamReader(sFrame, System.Text.Encoding.UTF8);
        string frame = sr.ReadToEnd();

        sr.Close();
        return(CreateSfx_embed(frame, compressed));
    }
Exemplo n.º 5
0
 public static string DeflateToJ85String(string input,int level)
 {
     byte[] data=System.Text.Encoding.UTF8.GetBytes(input);
     data=new Deflator().ZipDeflate(data,level);
     return ToEncode85String(data);
 }
Exemplo n.º 6
0
 public static string DeflateToBase64String(string input,int level)
 {
     byte[] data=System.Text.Encoding.UTF8.GetBytes(input);
     data=new Deflator().ZipDeflate(data,level);
     return System.Convert.ToBase64String(data);
 }