_read()

in ts/src/client.ts [46:82]


  _read() {
    if (this.streaming) {
      return;
    }

    const separator = this.boundary;
    if (this.index < this.keys.length) {
      const name = this.keys[this.index];
      const fieldValue = this.form[name];
      if (typeof fieldValue.filename === 'string' &&
        typeof fieldValue.contentType === 'string' &&
        fieldValue.content instanceof Readable) {
        let body =
          `--${separator}\r\n` +
          `Content-Disposition: form-data; name="${name}"; filename="${fieldValue.filename}"\r\n` +
          `Content-Type: ${fieldValue.contentType}\r\n\r\n`;
        this.push(Buffer.from(body));
        this.streaming = true;
        fieldValue.content.on('data', (chunk: any) => {
          this.push(chunk);
        });
        fieldValue.content.on('end', () => {
          this.index++;
          this.streaming = false;
          this.push('');
        });
      } else {
        this.push(Buffer.from(`--${separator}\r\n` +
          `Content-Disposition: form-data; name="${name}"\r\n\r\n` +
          `${fieldValue}\r\n`));
        this.index++;
      }
    } else {
      this.push(Buffer.from(`\r\n--${separator}--\r\n`));
      this.push(null);
    }
  }