public void StoredNonSeekableKnownSizeNoCrcEncrypted() { // This cant be stored directly as the crc is not known const int TargetSize = 24692; const string Password = "******"; MemoryStream ms = new MemoryStreamWithoutSeek(); using (ZipOutputStream outStream = new ZipOutputStream(ms)) { outStream.Password = Password; outStream.IsStreamOwner = false; ZipEntry entry = new ZipEntry("dummyfile.tst"); entry.CompressionMethod = CompressionMethod.Stored; // The bit thats in question is setting the size before its added to the archive. entry.Size = TargetSize; outStream.PutNextEntry(entry); Assert.AreEqual(CompressionMethod.Deflated, entry.CompressionMethod, "Entry should be stored"); Assert.AreEqual(-1, entry.CompressedSize, "Compressed size should be known"); System.Random rnd = new Random(); int size = TargetSize; byte[] original = new byte[size]; rnd.NextBytes(original); // Although this could be written in one chunk doing it in lumps // throws up buffering problems including with encryption the original // source for this change. int index = 0; while (size > 0) { int count = (size > 0x200) ? 0x200 : size; outStream.Write(original, index, count); size -= 0x200; index += count; } } Assert.IsTrue(ZipTesting.TestArchive(ms.ToArray(), Password)); }
public void Zip64Descriptor() { MemoryStream msw = new MemoryStreamWithoutSeek(); ZipOutputStream outStream = new ZipOutputStream(msw); outStream.UseZip64 = UseZip64.Off; outStream.IsStreamOwner = false; outStream.PutNextEntry(new ZipEntry("StripedMarlin")); outStream.WriteByte(89); outStream.Close(); Assert.IsTrue(ZipTesting.TestArchive(msw.ToArray())); msw = new MemoryStreamWithoutSeek(); outStream = new ZipOutputStream(msw); outStream.UseZip64 = UseZip64.On; outStream.IsStreamOwner = false; outStream.PutNextEntry(new ZipEntry("StripedMarlin")); outStream.WriteByte(89); outStream.Close(); Assert.IsTrue(ZipTesting.TestArchive(msw.ToArray())); }
public void ReadAndWriteZip64NonSeekable() { MemoryStream msw = new MemoryStreamWithoutSeek(); using (ZipOutputStream outStream = new ZipOutputStream(msw)) { outStream.UseZip64 = UseZip64.On; outStream.IsStreamOwner = false; outStream.PutNextEntry(new ZipEntry("StripedMarlin")); outStream.WriteByte(89); outStream.PutNextEntry(new ZipEntry("StripedMarlin2")); outStream.WriteByte(89); outStream.Close(); } Assert.IsTrue(ZipTesting.TestArchive(msw.ToArray())); msw.Position = 0; using (ZipInputStream zis = new ZipInputStream(msw)) { while ( zis.GetNextEntry() != null ) { int len = 0; int bufferSize = 1024; byte[] buffer = new byte[bufferSize]; while ((len = zis.Read(buffer, 0, bufferSize)) > 0) { // Reading the data is enough } } } }
public void EntryWithNoDataAndZip64() { MemoryStream msw = new MemoryStreamWithoutSeek(); ZipOutputStream outStream = new ZipOutputStream(msw); outStream.IsStreamOwner = false; ZipEntry ze = new ZipEntry("Striped Marlin"); ze.ForceZip64(); ze.Size = 0; outStream.PutNextEntry(ze); outStream.CloseEntry(); outStream.Finish(); outStream.Close(); Assert.IsTrue(ZipTesting.TestArchive(msw.ToArray())); }
public void Zip64Descriptor() { MemoryStream msw = new MemoryStreamWithoutSeek(); var outStream = new ZipOutputStream(msw); outStream.UseZip64 = UseZip64.Off; outStream.IsStreamOwner = false; outStream.PutNextEntry(new ZipEntry("StripedMarlin")); outStream.WriteByte(89); outStream.Close(); var ms = new MemoryStream(msw.ToArray()); using (var zf = new ZipFile(ms)) { Assert.IsTrue(zf.TestArchive(true)); } msw = new MemoryStreamWithoutSeek(); outStream = new ZipOutputStream(msw); outStream.UseZip64 = UseZip64.On; outStream.IsStreamOwner = false; outStream.PutNextEntry(new ZipEntry("StripedMarlin")); outStream.WriteByte(89); outStream.Close(); ms = new MemoryStream(msw.ToArray()); using (var zf = new ZipFile(ms)) { Assert.IsTrue(zf.TestArchive(true)); } }
public void EntryWithNoDataAndZip64() { MemoryStream msw = new MemoryStreamWithoutSeek(); var outStream = new ZipOutputStream(msw); outStream.IsStreamOwner = false; var ze = new ZipEntry("Striped Marlin"); ze.ForceZip64(); ze.Size = 0; outStream.PutNextEntry(ze); outStream.CloseEntry(); outStream.Finish(); outStream.Close(); var ms = new MemoryStream(msw.ToArray()); using (var zf = new ZipFile(ms)) { Assert.IsTrue(zf.TestArchive(true)); } }