Пример #1
0
        public void Load(FileStream stream)
        {
            using (var reader = new PrimitiveReader(stream, false))
            {
                foreach (var provider in providers)
                {
                    var tempFile = TemporaryFilesManager.Instance.GetTemporaryFile();
                    if (ConfigurationManager.Instance.Get("file-system", "use-cow", false))
                    {
                        FileCopier.Copy(stream.Name, tempFile, true);

                        var size          = reader.ReadInt64();
                        var localPosition = stream.Position;
                        reader.ReadBytes((int)size);
                        provider.BlobIsReady(tempFile, localPosition, size);
                    }
                    else
                    {
                        var size = reader.ReadInt64();
                        using (var fileStream = new FileStream(tempFile, FileMode.OpenOrCreate))
                        {
                            reader.CopyTo(fileStream, size);
                        }
                        provider.BlobIsReady(tempFile, 0, size);
                    }
                }
            }
        }
Пример #2
0
        public void ShouldThrowIfStreamPrematurelyFinishes()
        {
            var streamToRead  = new MemoryStream();
            var streamToWrite = new MemoryStream();

            using (var reader = new PrimitiveReader(streamToRead, buffered))
            {
                Assert.Throws <EndOfStreamException>(() => reader.CopyTo(streamToWrite, 100));
            }
        }
        public void Load(PrimitiveReader reader)
        {
            var fileName = TemporaryFilesManager.Instance.GetTemporaryFile();

            underlyingStream       = new FileStream(fileName, FileMode.OpenOrCreate);
            underlyingStreamOffset = 0;

            length      = reader.ReadInt64();
            PaddingByte = reader.ReadByte();
            var numberOfBytes = reader.ReadInt64();

            reader.CopyTo(underlyingStream, numberOfBytes);
            Position = reader.ReadInt64();
        }
Пример #4
0
        public void ShouldCopyFromStream()
        {
            var stream     = new MemoryStream();
            var testArray  = Enumerable.Range(0, 1000).Select(x => (byte)x).ToArray();
            var testStream = new MemoryStream(testArray);

            using (var writer = new PrimitiveWriter(stream, buffered))
            {
                writer.CopyFrom(testStream, testArray.Length);
            }
            stream.Seek(0, SeekOrigin.Begin);
            var secondStream = new MemoryStream(testArray.Length);

            using (var reader = new PrimitiveReader(stream, buffered))
            {
                reader.CopyTo(secondStream, testArray.Length);
            }
            CollectionAssert.AreEqual(testArray, secondStream.ToArray());
        }
 public void ShouldThrowIfStreamPrematurelyFinishes()
 {
     var streamToRead = new MemoryStream();
     var streamToWrite = new MemoryStream();
     using(var reader = new PrimitiveReader(streamToRead, buffered))
     {
         Assert.Throws<EndOfStreamException>(() => reader.CopyTo(streamToWrite, 100));
     }
 }
 public void ShouldCopyFromStream()
 {
     var stream = new MemoryStream();
     var testArray = Enumerable.Range(0, 1000).Select(x => (byte)x).ToArray();
     var testStream = new MemoryStream(testArray);
     using(var writer = new PrimitiveWriter(stream, buffered))
     {
         writer.CopyFrom(testStream, testArray.Length);
     }
     stream.Seek(0, SeekOrigin.Begin);
     var secondStream = new MemoryStream(testArray.Length);
     using(var reader = new PrimitiveReader(stream, buffered))
     {
         reader.CopyTo(secondStream, testArray.Length);
     }
     CollectionAssert.AreEqual(testArray, secondStream.ToArray());
 }