async write(data) {
    if (this.err !== null) throw this.err;
    if (data.length === 0) return 0;
    let totalBytesWritten = 0;
    let numBytesWritten = 0;
    while (data.byteLength > this.available()) {
      if (this.buffered() === 0) {
        // Large write, empty buffer.
        // Write directly from data to avoid copy.
        try {
          numBytesWritten = await this.writer.write(data);
        } catch (e) {
          this.err = e;
          throw e;
        }
      } else {
        numBytesWritten = copy(data, this.buf, this.usedBufferBytes);
        this.usedBufferBytes += numBytesWritten;
        await this.flush();
      }
      totalBytesWritten += numBytesWritten;
      data = data.subarray(numBytesWritten);
    }
    numBytesWritten = copy(data, this.buf, this.usedBufferBytes);
    this.usedBufferBytes += numBytesWritten;
    totalBytesWritten += numBytesWritten;
    return totalBytesWritten;
  }
/** Writes the contents of `data` into the buffer.  If the contents won't fully
   * fit into the buffer, those bytes that can are copied into the buffer, the
   * buffer is the flushed to the writer and the remaining bytes are copied into
   * the now empty buffer.
   *
   * @return the number of bytes written to the buffer.
   */
Writes the contents of `data` into the buffer.  If the contents won't fully
fit into the buffer, those bytes that can are copied into the buffer, the
buffer is the flushed to the writer and the remaining bytes are copied into
the now empty buffer.

@return the number of bytes written to the buffer.
Writes the contents of ` data ` into the buffer . If the contents won ' t fully fit into the buffer those bytes that can are copied into the buffer the buffer is the flushed to the writer and the remaining bytes are copied into the now empty buffer . @return the number of bytes written to the buffer .
async write(data) {
    if (this.err !== null) throw this.err;
    if (data.length === 0) return 0;
    let totalBytesWritten = 0;
    let numBytesWritten = 0;
    while (data.byteLength > this.available()) {
      if (this.buffered() === 0) {
        try {
          numBytesWritten = await this.writer.write(data);
        } catch (e) {
          this.err = e;
          throw e;
        }
      } else {
        numBytesWritten = copy(data, this.buf, this.usedBufferBytes);
        this.usedBufferBytes += numBytesWritten;
        await this.flush();
      }
      totalBytesWritten += numBytesWritten;
      data = data.subarray(numBytesWritten);
    }
    numBytesWritten = copy(data, this.buf, this.usedBufferBytes);
    this.usedBufferBytes += numBytesWritten;
    totalBytesWritten += numBytesWritten;
    return totalBytesWritten;
  }
async write ( data ) { if ( this . err !== null ) throw this . err ; if ( data . length === 0 ) return 0 ; let totalBytesWritten = 0 ; let numBytesWritten = 0 ; while ( data . byteLength > this . available ( ) ) { if ( this . buffered ( ) === 0 ) { try { numBytesWritten = await this . writer . write ( data ) ; } catch ( e ) { this . err = e ; throw e ; } } else { numBytesWritten = copy ( data , this . buf , this . usedBufferBytes ) ; this . usedBufferBytes += numBytesWritten ; await this . flush ( ) ; } totalBytesWritten += numBytesWritten ; data = data . subarray ( numBytesWritten ) ; } numBytesWritten = copy ( data , this . buf , this . usedBufferBytes ) ; this . usedBufferBytes += numBytesWritten ; totalBytesWritten += numBytesWritten ; return totalBytesWritten ; }
Writes the contents of `data` into the buffer.
Writes the contents of ` data ` into the buffer .
// Large write, empty buffer. // Write directly from data to avoid copy.