Пример #1
0
        public Result Write(long offset, ReadOnlySpan <byte> source, WriteOption options)
        {
            if (IsDisposed)
            {
                return(ResultFs.PreconditionViolation.Log());
            }

            if (source.Length == 0)
            {
                if (options.HasFlag(WriteOption.Flush))
                {
                    return(FlushImpl());
                }

                return(Result.Success);
            }

            if (offset < 0)
            {
                return(ResultFs.OutOfRange.Log());
            }
            if (long.MaxValue - offset < source.Length)
            {
                return(ResultFs.OutOfRange.Log());
            }

            return(WriteImpl(offset, source, options));
        }
Пример #2
0
        public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options)
        {
            ValidateWriteParams(source, offset);

            int  inPos     = 0;
            long outPos    = offset;
            int  remaining = source.Length;

            while (remaining > 0)
            {
                int   fileIndex  = GetSubFileIndexFromOffset(outPos);
                IFile file       = Sources[fileIndex];
                long  fileOffset = outPos - fileIndex * SubFileSize;

                long fileEndOffset = Math.Min((fileIndex + 1) * SubFileSize, GetSize());
                int  bytesToWrite  = (int)Math.Min(fileEndOffset - outPos, remaining);
                file.Write(source.Slice(inPos, bytesToWrite), fileOffset, options);

                outPos    += bytesToWrite;
                inPos     += bytesToWrite;
                remaining -= bytesToWrite;
            }

            if ((options & WriteOption.Flush) != 0)
            {
                Flush();
            }
        }
Пример #3
0
        public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options)
        {
#if STREAM_SPAN
            lock (Locker)
            {
                BaseStream.Position = offset;
                BaseStream.Write(source);
            }
#else
            byte[] buffer = ArrayPool <byte> .Shared.Rent(source.Length);

            try
            {
                source.CopyTo(buffer);

                lock (Locker)
                {
                    BaseStream.Position = offset;
                    BaseStream.Write(buffer, 0, source.Length);
                }
            }
            finally { ArrayPool <byte> .Shared.Return(buffer); }
#endif

            if ((options & WriteOption.Flush) != 0)
            {
                Flush();
            }
        }
Пример #4
0
        public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options)
        {
            ValidateWriteParams(source, offset);

            BaseStorage.Write(source, offset);

            if ((options & WriteOption.Flush) != 0)
            {
                Flush();
            }
        }
Пример #5
0
 public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options) =>
 ThrowHelper.ThrowResult(ResultFs.UnsupportedOperationModifyReadOnlyFile);
Пример #6
0
        public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options)
        {
            ValidateWriteParams(source, offset);

            File.Write(source, offset, options);
        }
        public Result WriteFile(FileHandle handle, long offset, ReadOnlySpan <byte> source, WriteOption option)
        {
            Result rc;

            if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle))
            {
                TimeSpan startTime = Time.GetCurrent();
                rc = handle.File.Write(offset, source, option);
                TimeSpan endTime = Time.GetCurrent();

                string optionString = (option & WriteOption.Flush) == 0 ? "" : $", write_option: {option}";

                OutputAccessLog(rc, startTime, endTime, handle, $", offset: {offset}, size: {source.Length}{optionString}");
            }
            else
            {
                rc = handle.File.Write(offset, source, option);
            }

            return(rc);
        }
Пример #8
0
        public void WriteFile(FileHandle handle, ReadOnlySpan <byte> source, long offset, WriteOption option)
        {
            if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle))
            {
                TimeSpan startTime = Time.GetCurrent();
                handle.File.Write(source, offset, option);
                TimeSpan endTime = Time.GetCurrent();

                string optionString = (option & WriteOption.Flush) == 0 ? "" : $", write_option: {option}";

                OutputAccessLog(startTime, endTime, handle, $", offset: {offset}, size: {source.Length}{optionString}");
            }
            else
            {
                handle.File.Write(source, offset, option);
            }
        }
Пример #9
0
 public abstract void Write(ReadOnlySpan <byte> source, long offset, WriteOption options);
Пример #10
0
 public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options)
 {
     throw new NotImplementedException();
 }
Пример #11
0
            protected override Result WriteImpl(long offset, ReadOnlySpan <byte> source, WriteOption options)
            {
                if (!Mode.HasFlag(OpenMode.Write))
                {
                    return(ResultFs.InvalidOpenModeForWrite.Log());
                }

                return(BaseStream.Write(offset, source, Mode.HasFlag(OpenMode.AllowAppend)));
            }
Пример #12
0
 protected abstract Result WriteImpl(long offset, ReadOnlySpan <byte> source, WriteOption options);
Пример #13
0
 public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options) => throw new NotSupportedException();
Пример #14
0
 public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options)
 {
     BaseFile.Write(source, offset, options);
 }