System.IO.Compression.CheckSumAndSizeWriteStream.Write C# (CSharp) Méthode

Write() public méthode

public Write ( byte buffer, int offset, int count ) : void
buffer byte
offset int
count int
Résultat void
        public override void Write(byte[] buffer, int offset, int count)
        {
            //we can't pass the argument checking down a level
            if (buffer == null)
                throw new ArgumentNullException(nameof(buffer));
            if (offset < 0)
                throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentNeedNonNegative);
            if (count < 0)
                throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentNeedNonNegative);
            if ((buffer.Length - offset) < count) 
                throw new ArgumentException(SR.OffsetLengthInvalid);
            Contract.EndContractBlock();

            //if we're not actually writing anything, we don't want to trigger as if we did write something
            ThrowIfDisposed();
            Debug.Assert(CanWrite);

            if (count == 0)
                return;

            if (!_everWritten)
            {
                _initialPosition = _baseBaseStream.Position;
                _everWritten = true;
            }

            _checksum = Crc32Helper.UpdateCrc32(_checksum, buffer, offset, count);
            _baseStream.Write(buffer, offset, count);
            _position += count;
        }

Usage Example

Exemple #1
0
            // careful: assumes that write is the only way to write to the stream, if writebyte/beginwrite are implemented
            // they must set _everWritten, etc.
            public override void Write(byte[] buffer, int offset, int count)
            {
                //we can't pass the argument checking down a level
                if (buffer == null)
                {
                    throw new ArgumentNullException(nameof(buffer));
                }
                if (offset < 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(offset));
                }
                if (count < 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(count));
                }
                if ((buffer.Length - offset) < count)
                {
                    throw new ArgumentException();
                }

                ThrowIfDisposed();
                Debug.Assert(CanWrite);

                // if we're not actually writing anything, we don't want to trigger the header
                if (count == 0)
                {
                    return;
                }

                if (!_everWritten)
                {
                    _everWritten = true;
                    // write local header, we are good to go
                    _usedZip64inLH = _entry.WriteLocalFileHeader(isEmptyFile: false);
                }

                _crcSizeStream.Write(buffer, offset, count);
                _position += count;
            }