Example #1
0
        void addFileFooter()
        {
            ZipDataFooter f = new ZipDataFooter();

            currentFile.WriteZipDataFooter(ref f);
            fifo.Write(Util.StructToByte(f));
        }
Example #2
0
        public void CalcChecksum()
        {
            TarHeader h2 = this;

            Array.Clear(h2.CheckSum, 0, h2.CheckSum.Length);
            byte[] data = Util.StructToByte(h2);
            SetChecksum(data);
        }
Example #3
0
        public void Finish()
        {
            long posStart = fifo.TotalWriteSize;

            foreach (File f in this.fileList)
            {
                ZipDirHeader d = new ZipDirHeader();
                d.Signature = 0x02014B50;                // ZipPacker.Signature;
                d.MadeVer   = Version;
                ZipDataHeader dh = new ZipDataHeader();
                f.WriteZipDataHeader(ref dh, true);
                if (f.Compress)
                {
                    dh.CompType = 8;
                    dh.CompSize = (uint)f.CompressSize;
                    dh.NeedVer  = ZipPacker.VersionWithCompress;
                }
                d.NeedVer     = dh.NeedVer;
                d.Option      = dh.Option;
                d.CompType    = dh.CompType;
                d.FileTime    = dh.FileTime;
                d.FileDate    = dh.FileDate;
                d.Crc32       = dh.Crc32;
                d.CompSize    = dh.CompSize;
                d.UncompSize  = dh.UncompSize;
                d.FileNameLen = dh.FileNameLen;
                d.ExtraLen    = dh.ExtraLen;
                d.CommentLen  = 0;
                d.DiskNum     = 0;
                d.InAttr      = 0;
                d.OutAttr     = (ushort)f.Attributes;
                d.HeaderPos   = f.HeaderPos;

                fifo.Write(Util.StructToByte(d));
                fifo.Write(this.Encoding.GetBytes(f.Name));
            }
            long posEnd = fifo.TotalWriteSize;

            ZipEndHeader e = new ZipEndHeader();

            e.Signature    = ZipPacker.SignatureEnd;
            e.DiskNum      = e.StartDiskNum = 0;
            e.DiskDirEntry = e.DirEntry = (ushort)this.fileList.Count;
            e.DirSize      = (uint)(posEnd - posStart);
            e.StartPos     = (uint)posStart;
            e.CommentLen   = 0;
            fifo.Write(Util.StructToByte(e));
        }
Example #4
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);
            }
        }
Example #5
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));
            }
        }
Example #6
0
        public void AddFileStart(string name, long size, DateTime dt, string directory_mode, string mode)
        {
            if (currentFileSize != 0 || currentPos != 0)
            {
                throw new ApplicationException("last file not completed.");
            }

            name = name.Replace('\\', '/');
            if (Str.InStr(name, "/", true))
            {
                AddDirectory(Path.GetDirectoryName(name), dt, directory_mode);
            }

            TarHeader h = TarUtil.CreateTarHeader(name, encoding, 0, size, dt, mode);

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

            currentFileSize = size;
            currentPos      = 0;
        }
Example #7
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));
        }
Example #8
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;
        }