web-csv-toolbox
    Preparing search index...

    Interface ParseBinaryOptions<Header, Delimiter, Quotation>

    Parse options for CSV binary.

    interface ParseBinaryOptions<
        Header extends ReadonlyArray<string> = ReadonlyArray<string>,
        Delimiter extends string = DEFAULT_DELIMITER,
        Quotation extends string = DEFAULT_QUOTATION,
    > {
        allowExperimentalCompressions?: boolean;
        charset?: string;
        decompression?: CompressionFormat;
        delimiter?: Delimiter;
        engine?: EngineConfig;
        fatal?: boolean;
        header?: Header;
        ignoreBOM?: boolean;
        maxBinarySize?: number;
        maxBufferSize?: number;
        maxFieldCount?: number;
        quotation?: Quotation;
        signal?: AbortSignal;
        skipEmptyLines?: boolean;
    }

    Type Parameters

    • Header extends ReadonlyArray<string> = ReadonlyArray<string>
    • Delimiter extends string = DEFAULT_DELIMITER
    • Quotation extends string = DEFAULT_QUOTATION

    Hierarchy (View Summary)

    Index

    Properties

    allowExperimentalCompressions?: boolean

    Allow experimental or non-standard compression formats not explicitly supported by this library.

    When true, compression formats from Content-Encoding headers that are not in the default supported list will be passed to the runtime's DecompressionStream without validation. This allows using compression formats that may not be universally supported across all browsers.

    When false (default), only universally supported formats are allowed:

    • Node.js: gzip, deflate, br (Brotli)
    • Browsers: gzip, deflate

    Some compression formats are only supported in specific environments:

    • deflate-raw: Supported in Chromium-based browsers (Chrome, Edge) but may not work in Firefox or Safari
    • br (Brotli): Future browser support may vary
    • Other formats: Depends on runtime implementation

    If you enable this option and use deflate-raw:

    • ✅ Works in Chrome, Edge (Chromium-based)
    • ❌ May fail in Firefox, Safari
    • Consider implementing fallback logic or detecting browser support at runtime

    Use with caution: Enabling this bypasses library validation and relies entirely on runtime error handling. If the runtime doesn't support the format, you'll get a runtime error instead of a clear validation error from this library.

    false
    
    // Safe mode (default): Only universally supported formats
    const response = await fetch('data.csv.gz');
    await parse(response); // ✓ Works in all browsers

    // Experimental mode: Allow deflate-raw (Chromium-only)
    const response = await fetch('data.csv'); // Content-Encoding: deflate-raw
    await parse(response, { allowExperimentalCompressions: true });
    // ✓ Works in Chrome/Edge
    // ✗ May fail in Firefox/Safari

    // Browser-aware usage
    const isChromium = navigator.userAgent.includes('Chrome');
    await parse(response, {
    allowExperimentalCompressions: isChromium
    });
    charset?: string

    You can specify the character encoding of the binary.

    TextDecoderStream is used internally.

    See Encoding API Compatibility for the encoding formats that can be specified.

    'utf-8'
    
    decompression?: CompressionFormat

    If the binary is compressed by a compression algorithm, the decompressed CSV can be parsed by specifying the algorithm.

    Make sure the runtime you are running supports stream decompression.

    See DecompressionStream Compatibility.

    delimiter?: Delimiter

    CSV field delimiter. If you want to parse TSV, specify '\t'.

    Detail restrictions are as follows:

    • Must not be empty
    • Must be a single character
      • Multi-byte characters are not supported
    • Must not include CR or LF
    • Must not be the same as the quotation
    ','
    
    engine?: EngineConfig

    Engine configuration for CSV parsing.

    parse(csv)
    
    parse(csv, { engine: { worker: true } })
    
    await loadWASM();
    parse(csv, { engine: { worker: true, wasm: true } })
    parse(csv, {
    engine: {
    worker: true,
    workerStrategy: "stream-transfer"
    }
    })
    fatal?: boolean

    If the binary has a invalid character, you can specify whether to throw an error.

    If the property is true then a decoder will throw a TypeError if it encounters malformed data while decoding.

    If false the decoder will substitute the invalid data with the replacement character U+FFFD (�).

    See TextDecoderOptions.fatal for more information.

    false
    
    header?: Header

    CSV header.

    If you specify this option, the first record will be treated as a normal record.

    If you don't specify this option, the first record will be treated as a header.

    undefined
    
    ignoreBOM?: boolean

    If the binary has a BOM, you can specify whether to ignore it.

    If you specify true, the BOM will be ignored. If you specify false or not specify it, the BOM will be treated as a normal character. See TextDecoderOptions.ignoreBOM for more information about the BOM.

    false
    
    maxBinarySize?: number

    Maximum binary size in bytes for ArrayBuffer/Uint8Array inputs.

    This option limits the size of ArrayBuffer or Uint8Array inputs to prevent memory exhaustion attacks. When the binary size exceeds this limit, a RangeError will be thrown.

    Set to Number.POSITIVE_INFINITY to disable the limit (not recommended for untrusted input).

    100 * 1024 * 1024 (100MB)
    
    maxBufferSize?: number

    Maximum internal buffer size in characters.

    This option limits the size of the internal buffer used during lexing to prevent memory exhaustion attacks. The buffer size is measured in UTF-16 code units (JavaScript string length). When the buffer exceeds this limit, a RangeError will be thrown.

    Set to Infinity to disable the limit (not recommended for untrusted input).

    10 * 1024 * 1024 (approximately 10MB for ASCII, but may vary for non-ASCII)
    
    maxFieldCount?: number

    Maximum number of fields allowed per record.

    This option limits the number of columns/fields in a CSV record to prevent memory exhaustion attacks. When a record exceeds this limit, a FieldCountLimitError will be thrown.

    Set to Number.POSITIVE_INFINITY to disable the limit (not recommended for untrusted input).

    100000
    
    quotation?: Quotation

    CSV field quotation.

    '"'
    
    signal?: AbortSignal

    The signal to abort the operation.

    If the signal is aborted, the operation will be stopped.

    const controller = new AbortController();

    const csv = "foo,bar\n1,2\n3,4";
    try {
    const result = await parse(csv, { signal: controller.signal });
    } catch (e) {
    if (e instanceof DOMException && e.name === "AbortError") {
    console.log("Aborted");
    }
    }

    // Abort with user action
    document.getElementById("cancel-button")
    .addEventListener("click", () => {
    controller.abort();
    });
    const csv = "foo,bar\n1,2\n3,4";

    try {
    const result = await parse(csv, { signal: AbortSignal.timeout(1000) });
    } catch (e) {
    if (e instanceof DOMException && e.name === "TimeoutError") {
    console.log("Timeout");
    }
    }
    undefined
    
    skipEmptyLines?: boolean

    When true, completely empty lines (with only delimiters or whitespace) will be skipped during parsing.

    false