コード例 #1
0
        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));
        }
コード例 #2
0
ファイル: ConcatenationFile.cs プロジェクト: tiliarou/nsZip
        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();
            }
        }
コード例 #3
0
        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();
            }
        }
コード例 #4
0
        public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options)
        {
            ValidateWriteParams(source, offset);

            BaseStorage.Write(source, offset);

            if ((options & WriteOption.Flush) != 0)
            {
                Flush();
            }
        }
コード例 #5
0
ファイル: ReadOnlyFile.cs プロジェクト: roblabla/LibHac
 public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options) =>
 ThrowHelper.ThrowResult(ResultFs.UnsupportedOperationModifyReadOnlyFile);
コード例 #6
0
ファイル: LocalFile.cs プロジェクト: AcK77/LibHac
        public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options)
        {
            ValidateWriteParams(source, offset);

            File.Write(source, offset, options);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: FileSystemManager.cs プロジェクト: tiliarou/nsZip
        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);
            }
        }
コード例 #9
0
ファイル: FileBase.cs プロジェクト: tiliarou/nsZip
 public abstract void Write(ReadOnlySpan <byte> source, long offset, WriteOption options);
コード例 #10
0
 public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options)
 {
     throw new NotImplementedException();
 }
コード例 #11
0
            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)));
            }
コード例 #12
0
ファイル: FileBase.cs プロジェクト: CaitSith2/libhac
 protected abstract Result WriteImpl(long offset, ReadOnlySpan <byte> source, WriteOption options);
コード例 #13
0
ファイル: ReadOnlyFile.cs プロジェクト: AcK77/LibHac
 public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options) => throw new NotSupportedException();
コード例 #14
0
 public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options)
 {
     BaseFile.Write(source, offset, options);
 }