Ejemplo n.º 1
0
            public async Task AllowsReadingOfZipCentralDirectory(string path)
            {
                // Arrange
                var originalStream = TestUtility.BufferTestData(path);
                var result         = await TestUtility.ReadWithMiniZipAsync(originalStream);

                var expected    = result.Data;
                var innerStream = new MemoryStream();

                var virtualOffset = (long)(expected.Zip64?.OffsetOfCentralDirectory ?? expected.OffsetOfCentralDirectory);

                originalStream.Position = virtualOffset;

                await originalStream.CopyToAsync(innerStream);

                var target       = new VirtualOffsetStream(innerStream, virtualOffset);
                var reader       = new ZipDirectoryReader(target);
                var expectedSize = originalStream.Length - virtualOffset;

                // Act
                var actual = await reader.ReadAsync();

                // Assert
                TestUtility.VerifyJsonEquals(expected, actual);
                Assert.Equal(expectedSize, innerStream.Length);
                Assert.Equal(originalStream.Length, target.Length);
            }
Ejemplo n.º 2
0
 public Facts()
 {
     _bytes         = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
     _innerStream   = new MemoryStream(_bytes);
     _virtualOffset = 20;
     _target        = new VirtualOffsetStream(_innerStream, _virtualOffset);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Wraps the provided <paramref name="srcStream"/> (which should be a stream written by
        /// <see cref="WriteAsync(Stream, Stream)"/>) in a virtual stream readable by most ZIP archive readers. For
        /// example, you can use <see cref="ZipDirectoryReader"/> to read the returned stream. The returned stream does
        /// not contain ZIP file entry contents and only contains the central directory.
        /// </summary>
        /// <param name="srcStream">The stream containing the "MZIP" format.</param>
        /// <returns>A stream readable as a ZIP archive with a central directory but no entries.</returns>
        public Task <Stream> ReadAsync(Stream srcStream)
        {
            using (var binaryReader = new BinaryReader(srcStream, Encoding.ASCII, leaveOpen: true))
            {
                // First, read the offset of the central directory.
                var virtualOffset = (long)binaryReader.ReadUInt64();

                // Next, wrap the rest of the stream as if it was at the end of the full ZIP file.
                var boundedStream = new BoundedStream(srcStream, srcStream.Position, srcStream.Length - 1);
                var outputStream  = new VirtualOffsetStream(boundedStream, virtualOffset);
                return(Task.FromResult <Stream>(outputStream));
            }
        }