CSVHandler
CSVHandler provides CSV import and export with automatic encoding conversion. It wraps the csv npm package and iconv-lite, defaulting to Windows-1250 encoding and semicolon delimiter — the standard for Czech CSV files.
Package: io-oidis-hub (backend only)
import { CSVHandler } from "@io-oidis-hub/Io/Oidis/Hub/IOApi/Handlers/CSVHandler.js";
Import
Parse a CSV file or Buffer into an array of objects (keyed by column headers):
const csv : CSVHandler = new CSVHandler();
const records : any[] = await csv.Import("/path/to/file.csv");
From Buffer
const buffer : Buffer = getFileBuffer();
const records : any[] = await csv.Import(buffer);
Custom Options
const records : any[] = await csv.Import(buffer, {
encoding: "utf8",
delimiter: ",",
skipEmptyLines: true,
relaxColumnCount: true,
progress: ($data : IFetchProgress) : void => {
LogIt.Info(`Processed ${$data.index} of ${$data.from} rows`);
}
});
ICSVImportOptions
| Option | Type | Default | Description |
|---|---|---|---|
encoding | string | "win1250" | Input encoding (iconv-lite codec) |
delimiter | string | ";" | Column separator |
skipEmptyLines | boolean | true | Skip blank lines |
relaxColumnCount | boolean | true | Allow rows with fewer/more columns than header |
progress | ($data : IFetchProgress) => void | null | Progress callback (index/from) |
Export
Generate a CSV file from structured data:
const csv : CSVHandler = new CSVHandler();
const result : IExportStatus = await csv.Export({
columns: ["name", "ean", "type"],
rows: [
{name: "Site A", ean: "859182400...", type: "D"},
{name: "Site B", ean: "859182400...", type: "O"}
]
}, ($progress : IFetchProgress) : void => {
LogIt.Info(`Export progress: ${$progress.index}/${$progress.from}`);
});
ICSVExportData
| Property | Type | Description |
|---|---|---|
rows | any[] | Array of data objects |
columns | string[] | Column keys to include (determines order) |
isPartial | boolean? | Flag for partial exports |
IExportStatus
The returned IExportStatus contains:
| Property | Type | Description |
|---|---|---|
id | string | SHA-1 based export identifier |
isPartial | boolean | Whether export was partial |
data | object | Contains data (base64 string or Buffer), encoding, format, name |
Export always encodes output to Windows-1250 with semicolon delimiter and includes a header row.
Notes
- CSVHandler is a backend-only utility — it requires Node.js
require()forcsvandiconv-litepackages - The
csvnpm package must be available in project dependencies - For frontend CSV parsing (e.g., user-uploaded files parsed in the browser), decode the file with
TextDecoderand send the string content to a backend method that usesCSVHandler
See also: Utilities Overview | FileSystemHandler | Convert