class IniLineDecoderStream
extends TransformStream<string, IniLine>

A transform stream that decodes lines of an INI file into structured objects.

Parses each input line and emits one of four line types:

Since this processes line by line, it preserves duplicate keys and sections. Input chunks are expected to be individual lines of text (use TextLineStream to split text into lines first).

Examples

Decode INI lines with various content types

import { assertEquals } from "@std/assert";
import { IniLineDecoderStream } from "@hertzg/wg-ini/lines";

const stream = ReadableStream.from([
  "# comment outside of section",
  "global_key=global_value # with comment",
  "duplicated=key",
  "duplicated=with other value",
  "[empty]",
  "[section with spaces] # and a comment",
  "key1=1",
  "key2=2",
  "[duplicated section]",
  "key1=1",
  "[duplicated section]",
  "key1=2",
]).pipeThrough(new IniLineDecoderStream());

const lines = await Array.fromAsync(stream);

assertEquals(lines, [
  { $comment: " comment outside of section" },
  { $assign: ["global_key", "global_value "], $comment: " with comment" },
  { $assign: ["duplicated", "key"], $comment: null },
  { $assign: ["duplicated", "with other value"], $comment: null },
  { $section: "empty", $trailer: "" },
  { $section: "section with spaces", $trailer: " # and a comment" },
  { $assign: ["key1", "1"], $comment: null },
  { $assign: ["key2", "2"], $comment: null },
  { $section: "duplicated section", $trailer: "" },
  { $assign: ["key1", "1"], $comment: null },
  { $section: "duplicated section", $trailer: "" },
  { $assign: ["key1", "2"], $comment: null },
]);

Constructors

IniLineDecoderStream(options?: IniLineDecoderStreamOptions)

Create a new INI line decoder stream.

Parameters

Configuration options for parsing delimiters.

Usage

import { IniLineDecoderStream } from "lines.ts";