Beispiel #1
0
        public ZipReturn ZipFileCreate(string newFilename, bool compressOutput, int dictionarySize = 1 << 24, int numFastBytes = 64)
        {
            if (ZipOpen != ZipOpenType.Closed)
            {
                return(ZipReturn.ZipFileAlreadyOpen);
            }

            DirUtil.CreateDirForFile(newFilename);
            _zipFileInfo = new FileInfo(newFilename);

            int errorCode = FileStream.OpenFileWrite(newFilename, out _zipFs);

            if (errorCode != 0)
            {
                ZipFileClose();
                return(ZipReturn.ZipErrorOpeningFile);
            }
            ZipOpen = ZipOpenType.OpenWrite;

            _signatureHeader = new SignatureHeader();
            _header          = new Header();

            using (BinaryWriter bw = new BinaryWriter(_zipFs, Encoding.UTF8, true))
            {
                _signatureHeader.Write(bw);
            }

            _baseOffset = _zipFs.Position;

            _compressed = compressOutput;

            _unpackedStreamSize = 0;
            if (_compressed)
            {
                LzmaEncoderProperties ep  = new LzmaEncoderProperties(true, dictionarySize, numFastBytes);
                LzmaStream            lzs = new LzmaStream(ep, false, _zipFs);
                _codeMSbytes = lzs.Properties;
                _lzmaStream  = lzs;


                /*
                 * ZstandardStream zss = new ZstandardStream(_zipFs, 22, true);
                 * _codeMSbytes = new byte[] { 1, 4, 18, 0, 0 };
                 * _lzmaStream = zss;
                 */
                _packStreamStart = (ulong)_zipFs.Position;
            }

            return(ZipReturn.ZipGood);
        }
Beispiel #2
0
        public ZipReturn ZipFileCreate(string newFilename, bool compressOutput)
        {
            if (ZipOpen != ZipOpenType.Closed)
            {
                return(ZipReturn.ZipFileAlreadyOpen);
            }

            DirUtil.CreateDirForFile(newFilename);
            _zipFileInfo = new FileInfo(newFilename);

            int errorCode = FileStream.OpenFileWrite(newFilename, out _zipFs);

            if (errorCode != 0)
            {
                ZipFileClose();
                return(ZipReturn.ZipErrorOpeningFile);
            }
            ZipOpen = ZipOpenType.OpenWrite;

            _signatureHeader = new SignatureHeader();
            _header          = new Header();

            BinaryWriter bw = new BinaryWriter(_zipFs);

            _signatureHeader.Write(bw);

            _compressed = compressOutput;

            _unpackedStreamSize = 0;
            if (_compressed)
            {
                LzmaEncoderProperties ep = new LzmaEncoderProperties(true, 1 << 24, 64);
                _lzmaStream      = new LzmaStream(ep, false, _zipFs);
                _codeMSbytes     = _lzmaStream.Properties;
                _packStreamStart = (ulong)_zipFs.Position;
            }

            return(ZipReturn.ZipGood);
        }