Exemple #1
0
        private Result ReadFile(out byte[] data)
        {
            Debug.Assert(FsClient != null);
            Debug.Assert(!string.IsNullOrWhiteSpace(FileName));

            data = default;

            Result rc = FsClient.OpenFile(out FileHandle handle, FileName, OpenMode.Read);

            if (rc.IsFailure())
            {
                return(rc);
            }

            rc = FsClient.GetFileSize(out long fileSize, handle);

            if (rc.IsSuccess())
            {
                data = new byte[fileSize];

                rc = FsClient.ReadFile(handle, 0, data);
            }

            FsClient.CloseFile(handle);
            return(rc);
        }
Exemple #2
0
        protected override Result DoRead(long offset, Span <byte> destination)
        {
            lock (_locker)
            {
                if (destination.Length == 0)
                {
                    return(Result.Success);
                }

                Result rc = UpdateSize();
                if (rc.IsFailure())
                {
                    return(rc);
                }

                if (!IsRangeValid(offset, destination.Length, FileSize))
                {
                    return(ResultFs.OutOfRange.Log());
                }

                return(FsClient.ReadFile(Handle, offset, destination));
            }
        }