class TsvParser {
  #currVal = "";
  #escaped = false;
  *parse(chunk) {
    let l = 0;
    let r = 0;
    for (; r < chunk.length; r++) {
      const ch = chunk[r];
      if (this.#escaped) {
        const escapedChar = ESCAPED_CHARACTERS[ch];
        if (escapedChar === void 0) {
          throw new Error(
            `Unexpected escape character \\${String.fromCharCode(ch)}`
          );
        }
        this.#currVal += escapedChar;
        l = r + 1;
        this.#escaped = false;
        continue;
      }
      switch (ch) {
        case 92:
          l < r && (this.#currVal += chunk.toString("utf8", l, r));
          l = r + 1;
          this.#escaped = true;
          break;
        case 9:
        // '\t'
        case 10:
          l < r && (this.#currVal += chunk.toString("utf8", l, r));
          l = r + 1;
          yield this.#currVal === NULL_BYTE ? null : this.#currVal;
          this.#currVal = "";
          break;
      }
    }
    l < r && (this.#currVal += chunk.toString("utf8", l, r));
  }
}
const NULL_BYTE = "\0";
const ESCAPED_CHARACTERS = {
  78: NULL_BYTE,
  // \N signifies the NULL character.
  92: "\\",
  98: "\b",
  102: "\f",
  110: "\n",
  114: "\r",
  116: "	",
  118: "\v"
};
export {
  NULL_BYTE,
  TsvParser
};
//# sourceMappingURL=pg-copy.js.map
