public void WriteFile(string filePath, Stream stream)
 {
     filePath = SanitizePath(filePath);
     DeleteFile(filePath);
     this.files.Add(new InMemoryVirtualFile(this, GetDirectory(GetDirPath(filePath)))
     {
         FilePath = filePath,
         ByteContents = stream.ReadFully(),
     });
 }
 public void WriteFile(string filePath, Stream stream)
 {
     filePath = SanitizePath(filePath);
     DeleteFile(filePath);
     this.files.Add(new InMemoryVirtualFile(this, CreateDirectory(GetDirPath(filePath)))
     {
         FilePath = filePath,
         ByteContents = stream.ReadFully(),
         FileLastModified = DateTime.UtcNow,
     });
 }
 public void AddFile(string filePath, Stream stream)
 {
     filePath = StripBeginningDirectorySeparator(filePath);
     this.files.Add(new InMemoryVirtualFile(VirtualPathProvider, this)
     {
         FilePath = filePath,
         FileName = filePath.Split(DirSeps).Last(),
         ByteContents = stream.ReadFully(),
     });
 }
Example #4
0
 private static ByteArrayContent FileDataContent(byte[] fileData=null, Stream srReader=null)
 {
     if (fileData!=null)
         return new ByteArrayContent(fileData);
     if (srReader == null) return null;
     var fd = srReader.ReadFully();
     return new ByteArrayContent(fd);
 }
        public void AppendFile(string filePath, Stream stream)
        {
            filePath = SanitizePath(filePath);

            var existingFile = GetFile(filePath);
            var bytes = existingFile != null
                ? existingFile.ReadAllBytes().Combine(stream.ReadFully())
                : stream.ReadFully();

            DeleteFile(filePath);

            this.files.Add(new InMemoryVirtualFile(this, CreateDirectory(GetDirPath(filePath)))
            {
                FilePath = filePath,
                ByteContents = bytes,
                FileLastModified = DateTime.UtcNow,
            });
        }
 public void WriteFile(string filePath, Stream stream)
 {
     var realFilePath = RootDir.RealPath.CombineWith(filePath);
     EnsureDirectory(Path.GetDirectoryName(realFilePath));
     File.WriteAllBytes(realFilePath, stream.ReadFully());
 }
Example #7
0
File: VInt.cs Project: juanii/NEbml
        /// <summary>
        /// Reads the value from the stream
        /// </summary>
        /// <param name="source"></param>
        /// <param name="maxLength">Maximal expected length (either 4 or 8)</param>
        /// <param name="buffer">The buffer for optimization purposes. Must match the maxlength</param>
        /// <returns></returns>
        public static VInt Read(Stream source, int maxLength, byte[] buffer)
        {
            buffer = buffer ?? new byte[maxLength];

            if (source.ReadFully(buffer, 0, 1) == 0)
            {
                throw new EndOfStreamException();
            }

            if(buffer[0] == 0)
                throw new EbmlDataFormatException("Length bigger than 8 are not supported");
            // TODO handle EBMLMaxSizeWidth

            var extraBytes = (buffer[0] & 0xf0) != 0
                ? ExtraBytesSize[buffer[0] >> 4]
                : 4 + ExtraBytesSize[buffer[0]];

            if (extraBytes + 1 > maxLength)
                throw new EbmlDataFormatException(string.Format("Expected VInt with a max length of {0}. Got {1}", maxLength, extraBytes + 1));

            if (source.ReadFully(buffer, 1, extraBytes) != extraBytes)
            {
                throw new EndOfStreamException();
            }

            ulong encodedValue = buffer[0];
            for (var i = 0; i < extraBytes; i++)
            {
                encodedValue = encodedValue << 8 | buffer[i + 1];
            }
            return new VInt(encodedValue, extraBytes + 1);
        }