Example #1
0
        // Token: 0x0600001E RID: 30 RVA: 0x000024BC File Offset: 0x000006BC
        public byte[] Unwrap(ArraySegment <byte> src, int maxDecompressedSize = 2147483647)
        {
            if (src.Count == 0)
            {
                return(new byte[0]);
            }
            ulong decompressedSize = Decompressor.GetDecompressedSize(src);

            if (decompressedSize == 0UL)
            {
                throw new ZstdException("Can't create buffer for data with unspecified decompressed size (provide your own buffer to Unwrap instead)");
            }
            if (decompressedSize > (ulong)((long)maxDecompressedSize))
            {
                throw new ArgumentOutOfRangeException(string.Format("Decompressed size is too big ({0} bytes > authorized {1} bytes)", decompressedSize, maxDecompressedSize));
            }
            byte[] array = new byte[decompressedSize];
            int    num;

            try
            {
                num = this.Unwrap(src, array, 0, false);
            }
            catch (InsufficientMemoryException)
            {
                throw new ZstdException("Invalid decompressed size");
            }
            if ((int)decompressedSize != num)
            {
                throw new ZstdException("Invalid decompressed size specified in the data");
            }
            return(array);
        }
Example #2
0
    /// <summary>
    /// 开始解压缩
    /// </summary>
    /// <param name="localFilePath"></param>
    /// <param name="buffer"></param>
    private void BeginDecompressExtract(string localFilePath, byte[] buffer)
    {
        try
        {
            using (var decompressor = new ZstdNet.Decompressor())
            {
                var path  = localFilePath;
                var bytes = decompressor.Unwrap(buffer);
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                File.WriteAllBytes(path, bytes);

                //下载文件中的MD5=未压缩时文件的MD5
                DownloadFileMD5 = MD5.ComputeHashString(bytes);
            }
        }
        catch (Exception e)
        {
            NotiData data = new NotiData(NotiConst.DOWNLOAD_EXTRACT_FAILED, this.FileName, e.Message);
            if (File.Exists(localFilePath))
            {
                File.Delete(localFilePath);
            }
            if (OnComplete != null)
            {
                OnComplete(data);                      //回调逻辑层
            }
        }
    }
Example #3
0
    public void ExecuteThreadedWork()
    {
        SubFileMD5Dic = new Dictionary <string, string>();
        try
        {
            FileMD5 = MD5.ComputeHashString(FileBytes);

            using (var decompressor = new ZstdNet.Decompressor())
            {
#if UNITY_IOS
                FileBytes = Crypto.Decode(FileBytes);
#endif
                using (var ms = new MemoryStream(decompressor.Unwrap(FileBytes)))
                {
                    using (var reader = new BinaryReader(ms))
                    {
                        while (reader.BaseStream.Position != reader.BaseStream.Length)
                        {
                            string abName = reader.ReadString();
                            int    length = reader.ReadInt32();
                            var    path   = LocalPath + abName;
                            string dir    = Path.GetDirectoryName(path);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            var bytes = reader.ReadBytes(length);
                            if (File.Exists(path))
                            {
                                File.Delete(path);
                            }
                            File.WriteAllBytes(path, bytes);

                            SubFileMD5Dic[abName] = MD5.ComputeHashString(bytes);
                        }
                    }
                }
            }
        }
        catch (Exception e)
        {
            var data = new NotiData(NotiConst.UPDATE_EXTRACT_FAILED, FileName, e.Message);
            if (OnComplete != null)
            {
                OnComplete(data);                      //回调逻辑层
            }
        }

        FileBytes = null;
    }
Example #4
0
 // Token: 0x0600001F RID: 31 RVA: 0x00002554 File Offset: 0x00000754
 public static ulong GetDecompressedSize(byte[] src)
 {
     return(Decompressor.GetDecompressedSize(new ArraySegment <byte>(src)));
 }