示例#1
0
        public void TestRoundtripPasswordProtectedArchive()
        {
            string entryName       = "TestFile";
            string entryData       = "TestData";
            string archivePassword = "******";
            //Zip up some data
            var testData     = Encoding.Unicode.GetBytes(entryData);
            var testFileData = new MemoryStream(testData);

            CyLR.archive.File file = new CyLR.archive.File(entryName, testFileData, new DateTime());
            var zipFile            = CreateZipArchive(new[] { file }, archivePassword);

            //Unzip that data
            var unzippedData = new MemoryStream();
            var unzippedFile = new ZipFile(zipFile);
            var unzipEntry   = unzippedFile.GetEntry(entryName);

            Assert.True(unzipEntry.IsFile);

            Assert.Throws <ZipException>(() =>
            {
                unzippedFile.GetInputStream(unzipEntry);
            });

            unzippedFile.Password = archivePassword;

            var unzipStream = unzippedFile.GetInputStream(unzipEntry);

            unzipStream.CopyTo(unzippedData);

            Assert.Equal(testData, unzippedData.ToArray());
        }
示例#2
0
        public void TestRoundtripArchive()
        {
            string entryName = "TestFile";
            string entryData = "TestData";
            //Zip up some data
            var testData     = Encoding.Unicode.GetBytes(entryData);
            var testFileData = new MemoryStream(testData);

            CyLR.archive.File file = new CyLR.archive.File(entryName, testFileData, new DateTime());
            var zipFile            = CreateZipArchive(new[] { file }, "");

            //Unzip that data
            var unzippedData = new MemoryStream();
            var unzippedFile = new ZipFile(zipFile);
            var unzipEntry   = unzippedFile.GetEntry(entryName);

            Assert.IsTrue(unzipEntry.IsFile);

            var unzipStream = unzippedFile.GetInputStream(unzipEntry);

            unzipStream.CopyTo(unzippedData);

            Assert.AreEqual(testData, unzippedData.ToArray());
        }