Ejemplo n.º 1
0
        public void CreateZipShouldLeaveOutputStreamOpenIfRequested(bool leaveOpen)
        {
            const string tempFileName = "a(2).dat";

            using (var tempFolder = new Utils.TempDir())
            {
                // Create test input file
                string addFile = Path.Combine(tempFolder.Fullpath, tempFileName);
                MakeTempFile(addFile, 16);

                // Create the zip with fast zip
                var target  = new TrackedMemoryStream();
                var fastZip = new FastZip();

                fastZip.CreateZip(target, tempFolder.Fullpath, false, @"a\(2\)\.dat", null, leaveOpen: leaveOpen);

                // Check that the output stream was disposed (or not) as expected
                Assert.That(target.IsDisposed, Is.Not.EqualTo(leaveOpen), "IsDisposed should be the opposite of leaveOpen");

                // Check that the file contents are correct in both cases
                var archive = new MemoryStream(target.ToArray());
                using (ZipFile zf = new ZipFile(archive))
                {
                    Assert.AreEqual(1, zf.Count);
                    ZipEntry entry = zf[0];
                    Assert.AreEqual(tempFileName, entry.Name);
                    Assert.AreEqual(16, entry.Size);
                    Assert.IsTrue(zf.TestArchive(true));
                }
            }
        }
Ejemplo n.º 2
0
        private byte[] MakeLocalHeader(string asciiName, short versionToExtract, short flags, short method,
                                       int dostime, int crc, int compressedSize, int size)
        {
            using (TrackedMemoryStream ms = new TrackedMemoryStream())
            {
                ms.WriteByte((byte)'P');
                ms.WriteByte((byte)'K');
                ms.WriteByte(3);
                ms.WriteByte(4);

                ms.WriteLEShort(versionToExtract);
                ms.WriteLEShort(flags);
                ms.WriteLEShort(method);
                ms.WriteLEInt(dostime);
                ms.WriteLEInt(crc);
                ms.WriteLEInt(compressedSize);
                ms.WriteLEInt(size);

                byte[] rawName = Encoding.ASCII.GetBytes(asciiName);
                ms.WriteLEShort((short)rawName.Length);
                ms.WriteLEShort(0);
                ms.Write(rawName, 0, rawName.Length);
                return(ms.ToArray());
            }
        }
Ejemplo n.º 3
0
        public void CreateZipShouldLeaveOutputStreamOpenIfRequested(bool leaveOpen)
        {
            const string tempFileName = "a(2).dat";

            using var tempFolder = Utils.GetTempDir();
            // Create test input file
            tempFolder.CreateDummyFile(tempFileName, size: 16);

            // Create the zip with fast zip
            var target  = new TrackedMemoryStream();
            var fastZip = new FastZip();

            fastZip.CreateZip(target, tempFolder, recurse: false, @"a\(2\)\.dat", directoryFilter: null, leaveOpen);

            // Check that the output stream was disposed (or not) as expected
            Assert.That(target.IsDisposed, Is.Not.EqualTo(leaveOpen), "IsDisposed should be the opposite of leaveOpen");

            // Check that the file contents are correct in both cases
            var archive = new MemoryStream(target.ToArray());

            using var zf = new ZipFile(archive);
            Assert.AreEqual(expected: 1, zf.Count);
            var entry = zf[0];

            Assert.AreEqual(tempFileName, entry.Name);
            Assert.AreEqual(expected: 16, entry.Size);
            Assert.IsTrue(zf.TestArchive(testData: true));
        }
Ejemplo n.º 4
0
        public void DoubleFooter()
        {
            var memStream = new TrackedMemoryStream();
            var s         = new GZipOutputStream(memStream);

            s.Finish();
            Int64 length = memStream.Length;

            s.Close();
            Assert.AreEqual(length, memStream.ToArray().Length);
        }
Ejemplo n.º 5
0
        public void DoubleFooter()
        {
            var memStream = new TrackedMemoryStream();
            var s         = new GZipOutputStream(memStream);

            s.Finish();
            Int64 length = memStream.Length;

#if NET451
            s.Close();
#elif NETCOREAPP1_0
            s.Dispose();
#endif
            Assert.AreEqual(length, memStream.ToArray().Length);
        }