public override int Read(Span <byte> destination, long offset, ReadOption options) { long inPos = offset; int outPos = 0; int remaining = ValidateReadParamsAndGetSize(destination, offset); while (remaining > 0) { int fileIndex = GetSubFileIndexFromOffset(offset); IFile file = Sources[fileIndex]; long fileOffset = offset - fileIndex * SubFileSize; long fileEndOffset = Math.Min((fileIndex + 1) * SubFileSize, GetSize()); int bytesToRead = (int)Math.Min(fileEndOffset - inPos, remaining); int bytesRead = file.Read(destination.Slice(outPos, bytesToRead), fileOffset, options); outPos += bytesRead; inPos += bytesRead; remaining -= bytesRead; if (bytesRead < bytesToRead) { break; } } return(outPos); }
public override int Read(Span <byte> destination, long offset, ReadOption options) { #if STREAM_SPAN lock (Locker) { if (BaseStream.Position != offset) { BaseStream.Position = offset; } return(BaseStream.Read(destination)); } #else byte[] buffer = ArrayPool <byte> .Shared.Rent(destination.Length); try { int bytesRead; lock (Locker) { if (BaseStream.Position != offset) { BaseStream.Position = offset; } bytesRead = BaseStream.Read(buffer, 0, destination.Length); } new Span <byte>(buffer, 0, destination.Length).CopyTo(destination); return(bytesRead); } finally { ArrayPool <byte> .Shared.Return(buffer); } #endif }
public override int Read(Span <byte> destination, long offset, ReadOption options) { int toRead = ValidateReadParamsAndGetSize(destination, offset); File.Read(destination.Slice(0, toRead), offset, options); return(toRead); }
public override int Read(Span <byte> destination, long offset, ReadOption options) { int toRead = ValidateReadParamsAndGetSize(destination, offset); long storageOffset = Offset + offset; BaseStorage.Read(destination.Slice(0, toRead), storageOffset); return(toRead); }
public int ReadFile(FileHandle handle, Span <byte> destination, long offset, ReadOption option) { int bytesRead; if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle)) { TimeSpan startTime = Time.GetCurrent(); bytesRead = handle.File.Read(destination, offset, option); TimeSpan endTime = Time.GetCurrent(); OutputAccessLog(startTime, endTime, handle, $", offset: {offset}, size: {destination.Length}"); } else { bytesRead = handle.File.Read(destination, offset, option); } return(bytesRead); }
public Result Read(out long bytesRead, long offset, Span <byte> destination, ReadOption options) { bytesRead = default; if (IsDisposed) { return(ResultFs.PreconditionViolation.Log()); } if (destination.Length == 0) { return(Result.Success); } if (offset < 0) { return(ResultFs.ValueOutOfRange.Log()); } return(ReadImpl(out bytesRead, offset, destination, options)); }
public override int Read(Span <byte> destination, long offset, ReadOption options) { return(BaseFile.Read(destination, offset, options)); }
public Result ReadFile(out long bytesRead, FileHandle handle, long offset, Span <byte> destination, ReadOption option) { Result rc; if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle)) { TimeSpan startTime = Time.GetCurrent(); rc = handle.File.Read(out bytesRead, offset, destination, option); TimeSpan endTime = Time.GetCurrent(); OutputAccessLog(rc, startTime, endTime, handle, $", offset: {offset}, size: {destination.Length}"); } else { rc = handle.File.Read(out bytesRead, offset, destination, option); } return(rc); }
public Result ReadFile(FileHandle handle, long offset, Span <byte> destination, ReadOption option) { Result rc = ReadFile(out long bytesRead, handle, offset, destination, option); if (rc.IsFailure()) { return(rc); } if (bytesRead == destination.Length) { return(Result.Success); } return(ResultFs.OutOfRange.Log()); }
public abstract int Read(Span <byte> destination, long offset, ReadOption options);
protected override Result ReadImpl(out long bytesRead, long offset, Span <byte> destination, ReadOption options) { if (!Mode.HasFlag(OpenMode.Read)) { bytesRead = 0; return(ResultFs.InvalidOpenModeForRead.Log()); } return(BaseStream.Read(out bytesRead, offset, destination)); }
protected abstract Result ReadImpl(out long bytesRead, long offset, Span <byte> destination, ReadOption options);