Ejemplo n.º 1
0
 private void TestAlignedReadStreamPosition(string inputfile, int bufferSize)
 {
     var buffer = new byte[1000];
     using (FileStream sourceFileStream = new FileStream(inputfile,
         FileMode.Open, FileAccess.Read, FileShare.None, bufferSize,
         Win32.FileFlagNoBuffering | FileOptions.SequentialScan))
     {
         using (AlignedReadStream readStream = new AlignedReadStream(sourceFileStream))
         {
             readStream.Seek(12, SeekOrigin.Begin);
             Assert.AreEqual(12, readStream.Position, "Invlid position");
             Assert.AreEqual(0, sourceFileStream.Position, "Invlid position");
             readStream.Seek(512, SeekOrigin.Begin);
             Assert.AreEqual(512, readStream.Position, "Invlid position");
             Assert.AreEqual(512, sourceFileStream.Position, "Invlid position");
             readStream.Seek(600, SeekOrigin.Begin);
             Assert.AreEqual(600, readStream.Position, "Invlid position");
             Assert.AreEqual(512, sourceFileStream.Position, "Invlid position");
             readStream.Seek(4096, SeekOrigin.Begin);
             Assert.AreEqual(4096, readStream.Position, "Invlid position");
             Assert.AreEqual(4096, sourceFileStream.Position, "Invlid position");
             readStream.Seek(-3000, SeekOrigin.Current);
             Assert.AreEqual(1096, readStream.Position, "Invlid position");
             Assert.AreEqual(1024, sourceFileStream.Position, "Invlid position");
             readStream.Seek(1024, SeekOrigin.Current);
             Assert.AreEqual(2120, readStream.Position, "Invlid position");
             Assert.AreEqual(2048, sourceFileStream.Position, "Invlid position");
             readStream.Seek(3385, SeekOrigin.Current);
             Assert.AreEqual(5505, readStream.Position, "Invlid position");
             Assert.AreEqual(5120, sourceFileStream.Position, "Invlid position");
             readStream.Seek(-100, SeekOrigin.End);
             Assert.AreEqual(readStream.Length - 100, readStream.Position, "Invlid position");
             Assert.AreEqual(sourceFileStream.Length - 100 - (sourceFileStream.Length - 100) % 512, sourceFileStream.Position, "Invlid position");
             readStream.Seek(-512, SeekOrigin.End);
             Assert.AreEqual(readStream.Length - 512, readStream.Position, "Invlid position");
             Assert.AreEqual(sourceFileStream.Length - 512 - (sourceFileStream.Length - 512) % 512, sourceFileStream.Position, "Invlid position");
             readStream.Seek(-2658, SeekOrigin.End);
             Assert.AreEqual(readStream.Length - 2658, readStream.Position, "Invlid position");
             Assert.AreEqual(sourceFileStream.Length - 2658 - (sourceFileStream.Length - 2658) % 512, sourceFileStream.Position, "Invlid position");
             readStream.Seek(0, SeekOrigin.Begin);
             Assert.AreEqual(0, readStream.Position, "Invlid position");
             Assert.AreEqual(0, sourceFileStream.Position, "Invlid position");
             readStream.Read(buffer, 0, buffer.Length);
             Assert.AreEqual(buffer.Length, readStream.Position, "Invlid position");
             Assert.AreEqual(buffer.Length + (512 - buffer.Length % 512), sourceFileStream.Position, "Invlid position");
             readStream.Read(buffer, 0, 4);
             Assert.AreEqual(buffer.Length + 4, readStream.Position, "Invlid position");
             Assert.AreEqual(buffer.Length + 4 + (512 - (buffer.Length + 4) % 512), sourceFileStream.Position, "Invlid position");
             readStream.Read(buffer, 0, 21);
             Assert.AreEqual(buffer.Length + 4 + 21, readStream.Position, "Invlid position");
             Assert.AreEqual(buffer.Length + 4 + 21 + (512 - (buffer.Length + 4 + 21) % 512), sourceFileStream.Position, "Invlid position");
             readStream.Read(buffer, 0, 1);
             Assert.AreEqual(buffer.Length + 4 + 21 + 1, readStream.Position, "Invlid position");
             Assert.AreEqual(buffer.Length + 4 + 21 + 1 + (512 - (buffer.Length + 4 + 21 + 1) % 512), sourceFileStream.Position, "Invlid position");
             readStream.Read(buffer, 0, 510);
             Assert.AreEqual(buffer.Length + 4 + 21 + 1 + 510, readStream.Position, "Invlid position");
             Assert.AreEqual(readStream.Position, sourceFileStream.Position, "Invlid position");
             readStream.Read(buffer, 0, 24);
             Assert.AreEqual(buffer.Length + 4 + 21 + 1 + 510 + 24, readStream.Position, "Invlid position");
             Assert.AreEqual(buffer.Length + 4 + 21 + 1 + 510 + 24 + (512 - (buffer.Length + 4 + 21 + 1 + 510 + 24) % 512), sourceFileStream.Position, "Invlid position");
             readStream.Read(buffer, 0, buffer.Length);
             Assert.AreEqual(2 * buffer.Length + 4 + 21 + 1 + 510 + 24, readStream.Position, "Invlid position");
             Assert.AreEqual(readStream.Position, sourceFileStream.Position, "Invlid position");
             readStream.Seek(0, SeekOrigin.End);
             Assert.AreEqual(readStream.Length, readStream.Position, "Invlid position");
             Assert.AreEqual(sourceFileStream.Length - (sourceFileStream.Length % 512), sourceFileStream.Position, "Invlid position");
             readStream.Read(buffer, 0, buffer.Length);
             Assert.AreEqual(readStream.Length, readStream.Position, "Invlid position");
             Assert.AreEqual(sourceFileStream.Length, sourceFileStream.Position, "Invlid position");
             readStream.Read(buffer, 0, buffer.Length);
             Assert.AreEqual(readStream.Length, readStream.Position, "Invlid position");
             Assert.AreEqual(sourceFileStream.Length, sourceFileStream.Position, "Invlid position");
             readStream.Seek(0, SeekOrigin.Begin);
             Assert.AreEqual(0, readStream.Position, "Invlid position");
             Assert.AreEqual(0, sourceFileStream.Position, "Invlid position");
             readStream.Seek(2, SeekOrigin.Begin);
             Assert.AreEqual(2, readStream.Position, "Invlid position");
             Assert.AreEqual(0, sourceFileStream.Position, "Invlid position");
             readStream.Read(buffer, 0, 10);
             Assert.AreEqual(12, readStream.Position, "Invlid position");
             Assert.AreEqual(512, sourceFileStream.Position, "Invlid position");
             readStream.Seek(500, SeekOrigin.Begin);
             Assert.AreEqual(500, readStream.Position, "Invlid position");
             Assert.AreEqual(512, sourceFileStream.Position, "Invlid position");
             readStream.Read(buffer, 0, 12);
             Assert.AreEqual(512, readStream.Position, "Invlid position");
             Assert.AreEqual(readStream.Position, sourceFileStream.Position, "Invlid position");
             readStream.Seek(-1 * readStream.Length % 512, SeekOrigin.End);
             Assert.AreEqual(readStream.Length - readStream.Length % 512, readStream.Position, "Invlid position");
             Assert.AreEqual(readStream.Position, sourceFileStream.Position, "Invlid position");
             readStream.Read(buffer, 0, 24);
             Assert.AreEqual((readStream.Length - readStream.Length % 512) + 24, readStream.Position, "Invlid position");
             Assert.AreEqual(sourceFileStream.Length, sourceFileStream.Position, "Invlid position");
             readStream.Seek(100, SeekOrigin.Current);
             Assert.AreEqual((readStream.Length - readStream.Length % 512) + 24 + 100, readStream.Position, "Invlid position");
             Assert.AreEqual(sourceFileStream.Length, sourceFileStream.Position, "Invlid position");
             readStream.Read(buffer, 0, 100);
             Assert.AreEqual((readStream.Length - readStream.Length % 512) + 24 + 100 + 100, readStream.Position, "Invlid position");
             Assert.AreEqual(sourceFileStream.Length, sourceFileStream.Position, "Invlid position");
             readStream.Seek(0, SeekOrigin.End);
             Assert.AreEqual(readStream.Length, readStream.Position, "Invlid position");
             Assert.AreEqual(sourceFileStream.Length, sourceFileStream.Position, "Invlid position");
         }
     }
 }
Ejemplo n.º 2
0
 private void TestReadData(AlignedReadStream readStream, byte[] data, int offset, int count)
 {
     var buffer = new byte[count];
     readStream.Seek(offset, SeekOrigin.Begin);
     readStream.Read(buffer, 0, count);
     Assert.IsTrue(buffer.SequenceEqual(data.Skip(offset).Take(count)), "Data mismatch");
 }
Ejemplo n.º 3
0
 protected void Check(FileStream fileStream, string password, int bufferSize)
 {
     using (AlignedReadStream readArchiveStream = new AlignedReadStream(fileStream, bufferSize))
     {
         readArchiveStream.Seek(0, SeekOrigin.Begin);
         SevenZipExtractor extractor = this.CreateExtractor(readArchiveStream, password);
         if (extractor.Check())
         {
             return;
         }
         throw new InvalidArchiveException();
     }
 }