Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
 public override int Read(Span <byte> destination, long offset, ReadOption options)
 {
     return(BaseFile.Read(destination, offset, options));
 }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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());
        }
Ejemplo n.º 10
0
 public abstract int Read(Span <byte> destination, long offset, ReadOption options);
Ejemplo n.º 11
0
            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));
            }
Ejemplo n.º 12
0
 protected abstract Result ReadImpl(out long bytesRead, long offset, Span <byte> destination, ReadOption options);