Esempio n. 1
0
        public ZipReturn ZipFileCloseWriteStream(byte[] crc32)
        {
            SevenZipLocalFile localFile = _localFiles[_localFiles.Count - 1];

            localFile.CRC = new[] { crc32[3], crc32[2], crc32[1], crc32[0] };

            if (unpackedStreamInfo != null)
            {
                unpackedStreamInfo.Crc = Util.BytesToUint(localFile.CRC);
            }

            return(ZipReturn.ZipGood);
        }
Esempio n. 2
0
        public ZipReturn ZipFileOpenWriteStream(bool raw, bool trrntzip, string filename, ulong uncompressedSize, ushort compressionMethod, out Stream stream, TimeStamps dateTime)
        {
            // check if we are writing a directory
            if (uncompressedSize == 0 && filename.Substring(filename.Length - 1, 1) == "/")
            {
                ZipFileAddDirectory(filename);
                stream = null;
                return(ZipReturn.ZipGood);
            }

            SevenZipLocalFile localFile = new()
            {
                Filename         = filename,
                UncompressedSize = uncompressedSize
            };

            _localFiles.Add(localFile);

            if (uncompressedSize == 0)
            {
                unpackedStreamInfo = null;
                stream             = null;
                return(ZipReturn.ZipGood);
            }


#if !solid
            outStreams newStream = new()
            {
                packedStart     = (ulong)_zipFs.Position,
                compType        = _compType,
                packedSize      = 0,
                unpackedStreams = new List <UnpackedStreamInfo>()
            };
            switch (_compType)
            {
            case SevenZipCompressType.lzma:

                LzmaEncoderProperties ep  = new(true, GetDictionarySizeFromUncompressedSize(uncompressedSize), 64);
                LzmaStream            lzs = new(ep, false, _zipFs);
                newStream.Method     = new byte[] { 3, 1, 1 };
                newStream.Properties = lzs.Properties;
                _compressStream      = lzs;
                break;

            case SevenZipCompressType.zstd:

                ZstdSharp.CompressionStream zss = new(_zipFs, 19);
                newStream.Method     = new byte[] { 4, 247, 17, 1 };
                newStream.Properties = new byte[] { 1, 5, 19, 0, 0 };
                _compressStream      = zss;
                break;

            case SevenZipCompressType.uncompressed:
                newStream.Method     = new byte[] { 0 };
                newStream.Properties = null;
                _compressStream      = _zipFs;
                break;
            }

            _packedOutStreams.Add(newStream);
#endif

            unpackedStreamInfo = new UnpackedStreamInfo {
                UnpackedSize = uncompressedSize
            };
            _packedOutStreams[_packedOutStreams.Count - 1].unpackedStreams.Add(unpackedStreamInfo);

            stream = _compressStream;
            return(ZipReturn.ZipGood);
        }

        public ZipReturn ZipFileCloseWriteStream(byte[] crc32)
        {
            SevenZipLocalFile localFile = _localFiles[_localFiles.Count - 1];

            localFile.CRC = new[] { crc32[3], crc32[2], crc32[1], crc32[0] };

            if (unpackedStreamInfo != null)
            {
                unpackedStreamInfo.Crc = Util.BytesToUint(localFile.CRC);
            }

#if !solid
            if (unpackedStreamInfo != null)
            {
                if (_packedOutStreams[_packedOutStreams.Count - 1].compType != SevenZipCompressType.uncompressed)
                {
                    _compressStream.Flush();
                    _compressStream.Close();
                }
                _packedOutStreams[_packedOutStreams.Count - 1].packedSize = (ulong)_zipFs.Position - _packedOutStreams[_packedOutStreams.Count - 1].packedStart;
            }
#endif

            return(ZipReturn.ZipGood);
        }