示例#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);
        }
示例#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
        }
示例#3
0
文件: LocalFile.cs 项目: AcK77/LibHac
        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);
        }
示例#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);
        }
示例#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);
        }
示例#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));
        }
示例#7
0
 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());
        }
示例#10
0
 public abstract int Read(Span <byte> destination, long offset, ReadOption options);
示例#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));
            }
示例#12
0
 protected abstract Result ReadImpl(out long bytesRead, long offset, Span <byte> destination, ReadOption options);