void WriteHeader()
 {
     EnsureDataMessage();
     _buf.WriteBytes(NpgsqlRawCopyStream.BinarySignature, 0, NpgsqlRawCopyStream.BinarySignature.Length);
     _buf.WriteInt32(0);   // Flags field. OID inclusion not supported at the moment.
     _buf.WriteInt32(0);   // Header extension area length
 }
Beispiel #2
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            CheckDisposed();
            if (!CanWrite)
            {
                throw new InvalidOperationException("Stream not open for writing");
            }

            if (count == 0)
            {
                return;
            }

            EnsureDataMessage();

            if (count <= _buf.WriteSpaceLeft)
            {
                _buf.WriteBytes(buffer, offset, count);
                return;
            }

            try {
                // Value is too big. Flush whatever is in the buffer, then write a new CopyData
                // directly with the buffer.
                Flush();

                _buf.WriteByte((byte)BackendMessageCode.CopyData);
                _buf.WriteInt32(count + 4);
                _buf.Flush();
                _buf.Underlying.Write(buffer, offset, count);
                EnsureDataMessage();
            } catch {
                _connector.Break();
                Cleanup();
                throw;
            }
        }