Ejemplo n.º 1
0
        public void AddDirectory(string name, DateTime dt, string mode)
        {
            name = name.Replace('\\', '/');
            if (name.EndsWith("/") == false)
            {
                name = name + "/";
            }

            if (dirList.ContainsKey(name) == false)
            {
                TarHeader h = TarUtil.CreateTarHeader(name, encoding, 5, 0, dt, mode);
                fifo.Write(Util.StructToByte(h));

                dirList.Add(name, 0);
            }
        }
Ejemplo n.º 2
0
        public void Write(byte[] data, int pos, int len, bool finish)
        {
            byte[] srcData = Util.ExtractByteArray(data, pos, len);
            byte[] dstData = new byte[srcData.Length * 2 + 100];

            if (this.finished)
            {
                throw new ApplicationException("already finished");
            }

            zs.next_in       = srcData;
            zs.avail_in      = srcData.Length;
            zs.next_in_index = 0;

            zs.next_out       = dstData;
            zs.avail_out      = dstData.Length;
            zs.next_out_index = 0;

            if (finish)
            {
                zs.deflate(zlibConst.Z_FINISH);
            }
            else
            {
                zs.deflate(zlibConst.Z_SYNC_FLUSH);
            }

            fifo.Write(dstData, 0, dstData.Length - zs.avail_out);

            currentSize += len;

            this.crc32 = ZipUtil.Crc32Next(data, pos, len, this.crc32);

            if (finish)
            {
                this.finished = true;
                this.crc32    = ~this.crc32;

                GZipFooter f = new GZipFooter();
                f.CRC32 = this.crc32;
                f.ISIZE = (uint)(this.currentSize % 0x100000000);

                fifo.Write(Util.StructToByte(f));
            }
        }
Ejemplo n.º 3
0
        public void AddFileStart(string name, long size, DateTime dt, FileAttributes attribute, bool compress)
        {
            if (currentFile != null)
            {
                throw new ApplicationException("currentFile != null");
            }

            name = name.Replace("/", "\\");

            File f = new File();

            f.Encoding   = this.Encoding;
            f.Name       = name;
            f.Size       = size;
            f.DateTime   = dt;
            f.Attributes = attribute;
            f.Compress   = compress;

            this.fileList.Add(f);

            ZipDataHeader h = new ZipDataHeader();

            f.HeaderPos = (uint)fifo.TotalWriteSize;
            f.WriteZipDataHeader(ref h, false);
            fifo.Write(Util.StructToByte(h));
            fifo.Write(this.Encoding.GetBytes(f.Name));
            f.Crc32 = 0xffffffff;

            if (compress)
            {
                f.ZStream = new CoreUtil.Internal.ZStream();
                f.ZStream.deflateInit(-1, -15);
            }

            currentFile = f;
        }
Ejemplo n.º 4
0
        public GZipPacker()
        {
            fifo = new Fifo();

            zs = new ZStream();
            zs.deflateInit(-1, -15);

            this.currentSize = 0;
            this.crc32       = 0xffffffff;
            this.finished    = false;

            GZipHeader h = new GZipHeader();

            h.ID1   = 0x1f;
            h.ID2   = 0x8b;
            h.FLG   = 0;
            h.MTIME = Util.DateTimeToUnixTime(DateTime.Now.ToUniversalTime());
            h.XFL   = 0;
            h.OS    = 3;
            h.CM    = 8;

            fifo.Write(Util.StructToByte(h));
        }
Ejemplo n.º 5
0
		public GZipPacker()
		{
			fifo = new Fifo();

			zs = new ZStream();
			zs.deflateInit(-1, -15);

			this.currentSize = 0;
			this.crc32 = 0xffffffff;
			this.finished = false;

			GZipHeader h = new GZipHeader();
			h.ID1 = 0x1f;
			h.ID2 = 0x8b;
			h.FLG = 0;
			h.MTIME = Util.DateTimeToUnixTime(DateTime.Now.ToUniversalTime());
			h.XFL = 0;
			h.OS = 3;
			h.CM = 8;

			fifo.Write(Util.StructToByte(h));
		}