Пример #1
0
        /// <summary>
        /// 压缩数组
        /// </summary>
        /// <param name="input">数组</param>
        /// <returns>结果</returns>
        public static byte[] Compress(byte[] input)
        {
            string filename   = FileEx.TempFileName();
            string filename7z = FileEx.TempFileName();

            File.WriteAllBytes(filename, input);
            ZipFile(filename, filename7z);
            byte[] bts = File.ReadAllBytes(filename7z);
            FileEx.TryDelete(filename);
            FileEx.TryDelete(filename7z);
            return(bts);
        }
Пример #2
0
        /// <summary>
        /// 解压缩数组
        /// </summary>
        /// <param name="input">数组</param>
        /// <returns>结果</returns>
        public static byte[] Decompress(byte[] input)
        {
            string zipfile = FileEx.TempFileName();

            File.WriteAllBytes(zipfile, input);

            string unzipDir = DirEx.TempRandomPath();

            UnZipFile(zipfile, unzipDir);
            string[] fall      = Directory.GetFiles(unzipDir, "*.*", SearchOption.TopDirectoryOnly);
            string   unzipfile = fall[0];

            byte[] bts = File.ReadAllBytes(unzipfile);
            FileEx.TryDelete(unzipfile);
            FileEx.TryDelete(zipfile);
            DirEx.TryDelete(unzipDir);
            return(bts);
        }