Ejemplo n.º 1
0
 public void Save(Stream stream)
 {
     using (var writer = new PrimitiveWriter(stream, false))
     {
         foreach (var provider in providers)
         {
             var descriptor = provider.GetBlobDescriptor();
             writer.Write(descriptor.Size);
             writer.CopyFrom(descriptor.Stream, descriptor.Size);
         }
     }
 }
        public void Save(PrimitiveWriter writer)
        {
            // we don't have to save offset as after deserialization we will treat it as 0
            // we don't have to save paddingOffset as it will be recalculated by setting `Position` after deserialization
            writer.Write(Length);
            writer.Write(PaddingByte);
            var initialPosition = Position;

            // this seeks to the beginning of meaningful data in the stream
            Position = 0;
            writer.Write(underlyingStream.Length - underlyingStream.Position);
            writer.CopyFrom(underlyingStream, underlyingStream.Length - underlyingStream.Position);
            Position = initialPosition;
            writer.Write(initialPosition);
        }
Ejemplo n.º 3
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 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());
 }