コード例 #1
0
ファイル: ZipEntry.cs プロジェクト: hiling/WebZip
        private byte[] GetExtraField()
        {
            byte[] block = null;
            //var data = new System.Collections.Generic.List<byte>();
            if ((UsesEncryption) && (IsStrong(Encryption)))
            {
                // byte[] block= GetStrongEncryptionBlock();
                // return block;
            }

            #if INFOZIP_UTF8
            if (FileNameIsUtf8(FileNameChars))
            {
            _FilenameIsUtf8= true;
            int datasize= 2+2+1+4+FileNameChars.Length;
            block= new byte[datasize];
            int i=0, mark=0;
            uint d= (uint) (datasize -4);
            block[i++]= 0x75;
            block[i++]= 0x70;
            block[i++]= (byte)(d & 0x00FF);
            block[i++]= (byte)(d & 0xFF00);

            // version
            block[i++]= 1;

            // skip the CRC on the filenamebytes, for now
            mark = i;
            i+= 4;

            // UTF8 filename
            for (int j = 0; j < FileNameChars.Length; j++)
            {
            byte[] b = System.BitConverter.GetBytes(FileNameChars[j]);
            block[i++]= b[0];
            }

            // filename field Crc32 - for the non-UTF8 filename field
            CRC32 Crc32= new CRC32();
            Crc32.SlurpBlock(block, mark+4, FileNameChars.Length);
            i= mark;
            block[i++] = (byte)(Crc32.Crc32Result & 0x000000FF);
            block[i++] = (byte)((Crc32.Crc32Result & 0x0000FF00) >> 8);
            block[i++] = (byte)((Crc32.Crc32Result & 0x00FF0000) >> 16);
            block[i++] = (byte)((Crc32.Crc32Result & 0xFF000000) >> 24);
            }
            #endif

            // could inject other blocks here...

            return block;
        }
コード例 #2
0
ファイル: Crc32.cs プロジェクト: hiling/WebZip
 /// <summary>
 /// The constructor.
 /// </summary>
 /// <param name="stream">The underlying stream</param>
 /// <param name="length">The length of the stream to slurp</param>
 public CrcCalculatorStream(System.IO.Stream stream, int length)
     : base()
 {
     _InnerStream = stream;
     _Crc32 = new CRC32();
     _length = length;
 }
コード例 #3
0
ファイル: ZipEntry.cs プロジェクト: hiling/WebZip
        private Int32 FigureCrc32()
        {
            if (_crcCalculated == false)
            {
                Stream input = null;
                // get the original stream:
                if (_sourceStream != null)
                {
                    _sourceStream.Position = 0;
                    input = _sourceStream;
                }
                else
                {
                    input = System.IO.File.OpenRead(LocalFileName);
                }
                var crc32 = new CRC32();

                _Crc32 = crc32.GetCrc32(input);
                if (_sourceStream == null)
                {
                    input.Close();
                    input.Dispose();
                }
                _crcCalculated = true;
            }
            return _Crc32;
        }
コード例 #4
0
ファイル: Crc32.cs プロジェクト: hiling/WebZip
 /// <summary>
 /// The constructor.
 /// </summary>
 /// <param name="stream">The underlying stream</param>
 public CrcCalculatorStream(System.IO.Stream stream)
     : base()
 {
     _InnerStream = stream;
     _Crc32 = new CRC32();
 }