示例#1
0
        public override void SetLength(long value)
        {
            long distanceToMoveHigh;

            if (!NativeFile.SetFilePointerEx(this.handle, value, out distanceToMoveHigh, SeekOrigin.Begin))
            {
                throw new IOException("Unable to seek to this position", NativeFileStream.MarshalGetLastWin32Error());
            }
            if (!NativeFile.SetEndOfFile(this.handle))
            {
                throw new IOException("Unable to set the new length", NativeFileStream.MarshalGetLastWin32Error());
            }
            if (this.position < value)
            {
                this.Seek(this.position, SeekOrigin.Begin);
            }
            else
            {
                this.Seek(0L, SeekOrigin.End);
            }
        }
示例#2
0
        /// <inheritdoc/>
        public override void SetLength(long value)
        {
            long newPosition;

            if (!NativeFile.SetFilePointerEx(handle, value, out newPosition, SeekOrigin.Begin))
            {
                throw new IOException("Unable to seek to this position", MarshalGetLastWin32Error());
            }
            if (!NativeFile.SetEndOfFile(handle))
            {
                throw new IOException("Unable to set the new length", MarshalGetLastWin32Error());
            }

            if (position < value)
            {
                Seek(position, SeekOrigin.Begin);
            }
            else
            {
                Seek(0, SeekOrigin.End);
            }
        }