Example #1
0
        public long Crc32LargeUpdate()
        {
            var crc32 = new ICSharpCode.SharpZipLib.Checksum.Crc32();

            crc32.Update(data);
            return(crc32.Value);
        }
Example #2
0
        public void MatchesReference(int length)
        {
            var data = GetBuffer(length);
            var crc  = new SharpCrc32();

            crc.Update(data);

            long expected = crc.Value;
            long actual   = Crc32.Calculate(data);

            Assert.Equal(expected, actual);
        }
Example #3
0
        public static void ZipFile(System.Collections.Generic.List <string> filesToZip, string outFile, int compression = 3, bool IsMapPath = true)
        {
            outFile = IsMapPath ? TM.Core.IO.MapPath(outFile) : outFile;
            if (compression < 0 || compression > 9)
            {
                throw new ArgumentException("Invalid compression rate (just 0-9).");
            }

            if (!Directory.Exists(new FileInfo(outFile).Directory.ToString()))
            {
                throw new ArgumentException("The Path does not exist.");
            }

            foreach (string c in filesToZip)
            {
                if (!File.Exists(IsMapPath ? TM.Core.IO.MapPath(c) : c))
                {
                    throw new ArgumentException(string.Format("The File {0} does not exist!", c));
                }
            }

            var crc32  = new ICSharpCode.SharpZipLib.Checksum.Crc32();
            var stream = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(File.Create(outFile));

            stream.SetLevel(compression);

            for (int i = 0; i < filesToZip.Count; i++)
            {
                var entry = new ICSharpCode.SharpZipLib.Zip.ZipEntry(Path.GetFileName(filesToZip[i]));
                entry.DateTime = DateTime.Now;
                var _filesToZip = IsMapPath ? TM.Core.IO.MapPath(filesToZip[i]) : filesToZip[i];
                using (FileStream fs = File.OpenRead(_filesToZip))
                {
                    byte[] buffer = new byte[fs.Length];
                    fs.Read(buffer, 0, buffer.Length);
                    entry.Size = fs.Length;
                    fs.Close();
                    crc32.Reset();
                    crc32.Update(buffer);
                    entry.Crc = crc32.Value;
                    stream.PutNextEntry(entry);
                    stream.Write(buffer, 0, buffer.Length);
                }
            }
            stream.Finish();
            stream.Close();
        }