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)); }
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(); } }
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(); } }
public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options) { ValidateWriteParams(source, offset); BaseStorage.Write(source, offset); if ((options & WriteOption.Flush) != 0) { Flush(); } }
public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options) => ThrowHelper.ThrowResult(ResultFs.UnsupportedOperationModifyReadOnlyFile);
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); }
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); } }
public abstract void Write(ReadOnlySpan <byte> source, long offset, WriteOption options);
public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options) { throw new NotImplementedException(); }
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))); }
protected abstract Result WriteImpl(long offset, ReadOnlySpan <byte> source, WriteOption options);
public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options) => throw new NotSupportedException();
public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options) { BaseFile.Write(source, offset, options); }