Exemplo n.º 1
0
        byte[] MakeMemZip(ref byte[] original, CompressionMethod method, int compressionLevel, int size, string password, bool withSeek)
        {
            MemoryStream ms;

            if (withSeek == true) {
                ms = new MemoryStream();
            } else {
                ms = new MemStreamWithoutSeek();
            }

            ZipOutputStream outStream = new ZipOutputStream(ms);
            if (password != null) {
                outStream.Password = password;
            }

            if (method != CompressionMethod.Stored)
                outStream.SetLevel(compressionLevel); // 0 - store only to 9 - means best compression

            ZipEntry entry = new ZipEntry("dummyfile.tst");
            entry.CompressionMethod = method;

            outStream.PutNextEntry(entry);

            if (size > 0) {
                original = new byte[size];
                System.Random rnd = new Random();
                rnd.NextBytes(original);

                outStream.Write(original, 0, original.Length);
            }
            outStream.Close();
            return ms.GetBuffer();
        }
Exemplo n.º 2
0
        public void StoredNonSeekableConvertToDeflate()
        {
            MemStreamWithoutSeek ms = new MemStreamWithoutSeek();

            ZipOutputStream outStream = new ZipOutputStream(ms);
            outStream.SetLevel(8);
            Assert.AreEqual(8, outStream.GetLevel(), "Compression level invalid");

            ZipEntry entry = new ZipEntry("1.tst");
            entry.CompressionMethod = CompressionMethod.Stored;
            outStream.PutNextEntry(entry);
            Assert.AreEqual(0, outStream.GetLevel(), "Compression level invalid");

            AddRandomDataToEntry(outStream, 100);
            entry = new ZipEntry("2.tst");
            entry.CompressionMethod = CompressionMethod.Deflated;
            outStream.PutNextEntry(entry);
            Assert.AreEqual(8, outStream.GetLevel(), "Compression level invalid");
            AddRandomDataToEntry(outStream, 100);

            outStream.Close();
        }