Beispiel #1
0
        /// <inheritdoc />
        public byte[] ReadAllBytes(AbsolutePath path)
        {
            using (FileObject.FileMemoryStream fileStream = OpenStreamInternal(path, FileAccess.Read, FileMode.Open, FileShare.Read))
            {
                if (fileStream == null)
                {
                    throw new FileNotFoundException($"Could not find file '{path}'");
                }

                return(fileStream.ToArray());
            }
        }
Beispiel #2
0
        /// <inheritdoc />
        public void WriteAllBytes(AbsolutePath path, byte[] content)
        {
            if (FileExists(path.Parent))
            {
                throw new DirectoryNotFoundException();
            }

            using (FileObject.FileMemoryStream fileStream =
                       OpenStreamInternal(path, FileAccess.Write, FileMode.OpenOrCreate, FileShare.Read))
            {
                if (fileStream == null)
                {
                    throw new DirectoryNotFoundException($"Could not find directory '{path}'");
                }

                fileStream.SetLength(content.LongLength);
                using (var sourceStream = new MemoryStream(content))
                {
                    sourceStream.CopyTo(fileStream);
                }
            }
        }