edf2csv 0.9.37 → 0.9.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/convert/run.js +30 -0
- package/dist/convert/run.js.map +1 -1
- package/package.json +1 -1
package/dist/convert/run.js
CHANGED
|
@@ -2071,6 +2071,36 @@ export function withSidecarsNamed(diagnostics, { toStdout, gzip }) {
|
|
|
2071
2071
|
: `It is described in ${channels} but left out of the converted data.`,
|
|
2072
2072
|
};
|
|
2073
2073
|
}
|
|
2074
|
+
/*
|
|
2075
|
+
And the other `NO_SAMPLES`, whose whole hint is the two files written instead.
|
|
2076
|
+
|
|
2077
|
+
`noSignalFile` says where the signal data went for a recording that has none, and for
|
|
2078
|
+
the one shape of that — a file holding nothing but EDF+ annotations — the reassurance
|
|
2079
|
+
is a list of what the run does write. `--stdout` writes neither, and refuses the run
|
|
2080
|
+
outright, which the warning under it then says:
|
|
2081
|
+
|
|
2082
|
+
$ edf2csv scoring.edf --info --stdout
|
|
2083
|
+
warning: No signal file is written: there is no signal data in this recording
|
|
2084
|
+
to put in one.
|
|
2085
|
+
annotations.csv holds whatever events it carries. channels.csv lists
|
|
2086
|
+
signal channels, so it has none to list.
|
|
2087
|
+
warning: --stdout would refuse this run: has no signal data to write: this
|
|
2088
|
+
recording has no signal channels, only EDF+ annotations.
|
|
2089
|
+
Convert to a directory to get its annotations.csv, or drop --stdout.
|
|
2090
|
+
|
|
2091
|
+
Two consecutive warnings, the first offering the file the second says to convert to a
|
|
2092
|
+
directory to get. Named as the conversion that does write them, which is that advice.
|
|
2093
|
+
*/
|
|
2094
|
+
if (toStdout &&
|
|
2095
|
+
diagnostic.code === 'NO_SAMPLES' &&
|
|
2096
|
+
diagnostic.hint?.includes('holds whatever events it carries') === true) {
|
|
2097
|
+
return {
|
|
2098
|
+
...diagnostic,
|
|
2099
|
+
hint: `--stdout writes neither: a conversion to a directory gets ${annotations} with ` +
|
|
2100
|
+
`whatever events this recording carries, and a ${channels} with no signal ` +
|
|
2101
|
+
'channels to list.',
|
|
2102
|
+
};
|
|
2103
|
+
}
|
|
2074
2104
|
/*
|
|
2075
2105
|
The collision hint, whose whole advice is a file to look the channel up in.
|
|
2076
2106
|
|
package/dist/convert/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/convert/run.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,yFAAyF;AACzF,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAGrD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE3G,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,QAAQ,EACR,MAAM,EACN,cAAc,GACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC1F,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,KAAK,GACN,MAAM,qBAAqB,CAAC;AAE7B,OA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ing a conversion.\n *\n * Everything is written in a single pass over the data records. All rate groups are\n * open at once and fed from the same batch of bytes, so a file is read once no\n * matter how many output tables it produces, and memory stays flat.\n */\n\nimport { createWriteStream, fstatSync } from 'node:fs';\nimport { lstat, mkdir, readdir, stat, writeFile } from 'node:fs/promises';\nimport { finished } from 'node:stream/promises';\nimport type { Writable } from 'node:stream';\nimport { createGzip, gzipSync } from 'node:zlib';\nimport path from 'node:path';\n\n// A destination is whatever the caller's shell handed over; see printable's own comment.\nimport { printable } from '../format/unprintable.js';\n\nimport type { RecordBatch } from '../edf/reader.js';\nimport { EdfFile } from '../edf/reader.js';\nimport { describeFormat, formatRate, formatRates, formatWallClock, startsFormula } from '../edf/header.js';\nimport type { Diagnostic } from '../edf/errors.js';\nimport { EdfError } from '../edf/errors.js';\nimport type { Annotation } from '../edf/annotations.js';\nimport {\n BufferedLineWriter,\n DEFAULT_FLUSH_THRESHOLD,\n UTF8_BOM,\n csvRow,\n escapeCsvField,\n} from '../format/csv.js';\nimport { counted, grouped, listed } from '../format/list.js';\nimport { escapeCharacter, escapeJsonText, unprintableIn } from '../format/unprintable.js';\nimport {\n makeSampleFormatter,\n makeTimeFormatter,\n newOffsetBudget,\n newSampleCacheBudget,\n plain,\n} from '../format/number.js';\nimport type { SampleFormatter } from '../format/number.js';\nimport { TIME_COLUMN } from './channels.js';\nimport { assertInputPath, assertOptions } from './options.js';\nimport { buildPlan, outputCsvName, withoutFileRateWarning } from './plan.js';\nimport type { ConversionPlan, PlanOptions, RateGroup } from './plan.js';\nimport { deriveRecordStarts, withTimingPromiseKept } from './timing.js';\nimport { sampleTimeIsInRange, toleranceFor } from './time-range.js';\nimport { VERSION as TOOL_VERSION } from '../version.js';\n\nexport { TOOL_VERSION };\n\nexport type ConversionErrorCode =\n | 'OUTPUT_EXISTS'\n | 'OUTPUT_UNWRITABLE'\n | 'INPUT_OUTPUT_COLLISION'\n | 'INPUT_UNREADABLE'\n | 'UNSUPPORTED_REQUEST'\n | 'CALLBACK_FAILED'\n | 'WRITE_FAILED';\n\n/**\n * Codes that mean the command cannot be carried out as written, rather than that something\n * about the file or the destination went wrong.\n *\n * The distinction is the one the exit codes draw: 1 is \"the file or the destination is the\n * problem\", 2 is \"the command line is the problem\". A caller with a `--stdout` conflict is\n * being told to change the flags — the hints say exactly that — so filing it under 1 sent\n * scripts looking at the disk. Exit 2 already covers checks that need the header first,\n * such as a `--channels` term matching nothing.\n */\nexport const USAGE_ERROR_CODES: ReadonlySet<ConversionErrorCode> = new Set(['UNSUPPORTED_REQUEST']);\n\nexport class ConversionError extends Error {\n readonly code: ConversionErrorCode;\n readonly hint: string | undefined;\n constructor(code: ConversionErrorCode, message: string, hint?: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'ConversionError';\n this.code = code;\n this.hint = hint;\n }\n}\n\nexport interface ConvertOptions extends PlanOptions {\n /**\n * Destination directory. Defaults to `defaultOutputDir(inputPath)`: the input's name with\n * its extension replaced by `_csv`, beside the input — `sleep-study.edf` gives\n * `sleep-study_csv`, not `sleep-study`.\n */\n outputDir?: string | undefined;\n /** Overwrite an existing output directory. */\n force?: boolean | undefined;\n /** Record a SHA-256 of the input in metadata.json. Costs one extra read of the file. */\n checksum?: boolean | undefined;\n /**\n * Write the signal CSV to stdout instead of to a directory.\n *\n * Only valid when the conversion produces exactly one signal file. In the default wide\n * layout a mixed-rate recording becomes several tables, and merging them into one stream\n * would mean inventing the samples this tool exists not to invent; `layout: 'long'` gives\n * one table for any recording, so it lifts the restriction. No sidecar files are written.\n */\n toStdout?: boolean | undefined;\n onProgress?: ((progress: ConversionProgress) => void) | undefined;\n}\n\nexport interface ConversionProgress {\n recordsDone: number;\n recordsTotal: number;\n bytesWritten: number;\n}\n\nexport interface WrittenFile {\n name: string;\n rows: number;\n}\n\nexport interface ConvertResult {\n outputDir: string;\n files: WrittenFile[];\n /**\n * True when a `--stdout` reader closed the pipe before the conversion finished.\n *\n * `edf2csv rec.edf --stdout | head -1` is an ordinary thing to type and not a failure, but\n * it is also not a conversion: the row count is rows formatted before the close was\n * noticed, which is neither the recording's total nor what the reader received.\n */\n readerHungUp: boolean;\n annotationCount: number;\n diagnostics: Diagnostic[];\n plan: ConversionPlan;\n file: EdfFile;\n elapsedMs: number;\n}\n\ninterface OpenGroup {\n group: RateGroup;\n writer: BufferedLineWriter;\n formatters: SampleFormatter[];\n formatTime: (recordStart: number, sample: number) => string;\n rows: number;\n /** Resolves once a compressed stream's bytes have reached the file behind it. */\n settled: Promise<void>;\n /** Detaches the compressor's error forwarding from a stream this tool does not own. */\n release: () => void;\n}\n\nexport async function convert(inputPath: string, options: ConvertOptions = {}): Promise<ConvertResult> {\n assertInputPath(inputPath);\n // And the bag behind it, here rather than at `buildPlan` below: `options.checksum` is read\n // before the plan is built, so a bag that is not one reached that line first. See\n // assertOptions for what a string in this position did.\n assertOptions(options);\n const startedAt = Date.now();\n const file = await EdfFile.open(inputPath);\n\n try {\n /*\n Hashed before a record is read, and only published if the file held still.\n\n A checksum taken afterwards cannot be trusted whichever descriptor it goes through. A\n file overwritten in place keeps its inode, so the open handle sees the new bytes too,\n and the old ones are simply gone — there is nowhere left to read what was converted.\n Taking it first at least means the hash describes the file the header was read from.\n\n What makes it a guarantee rather than a hope is the check at the end: if size or\n modification time moved at any point, the hash is dropped and the run says why. So\n `sha256` present means the file demonstrably did not change while it was read, and a\n recording still being written gets a null and a warning instead of a plausible hash of\n the wrong bytes. (A change reverted within the same modification timestamp would slip\n through; nothing short of copying the input first can close that.)\n */\n const checksumAtOpen = options.checksum === true ? await file.sha256() : null;\n\n // One pass over the annotation channel supplies everything annotation-related:\n // where each record sits in time, and the full event list. It reads the whole\n // file even when a window was requested, because an annotation inside the window\n // may be stored in a record outside it.\n const annotationData =\n file.annotationSignals.length > 0\n ? await file.readAnnotations()\n : { annotations: [] as Annotation[], recordStarts: [] as (number | null)[], malformed: 0 };\n\n const timing = deriveRecordStarts(file, annotationData);\n\n const plan = buildPlan(\n {\n signals: file.header.signals,\n recordDuration: file.header.recordDuration,\n recordCount: file.recordCount,\n hasAnnotationChannel: file.annotationSignals.length > 0,\n recordStarts: timing.starts,\n },\n options,\n );\n plan.diagnostics.push(...timing.diagnostics);\n\n if (options.toStdout === true) {\n const refusal = stdoutRefusal(file, plan);\n if (refusal) throw refusal;\n let readerHungUp = false;\n const written = await writeSignalFiles(file, plan, null, timing.starts, options, (hungUp) => {\n readerHungUp = hungUp;\n });\n if (await file.changedSinceOpen()) plan.diagnostics.push(inputChanged(false));\n return {\n outputDir: '-',\n files: written,\n readerHungUp,\n annotationCount: 0,\n // Over both lists, because the timing warnings are pushed onto the plan's.\n diagnostics: withSidecarsNamed(\n withSignalTableUnwritten(\n [\n ...withTimingPromiseKept(withoutFileRateWarning(file.diagnostics), timing.starts !== null),\n ...plan.diagnostics,\n ],\n plan.writeSignals,\n plan.gzip,\n convertedChannels(plan),\n true,\n ),\n { toStdout: true, gzip: plan.gzip },\n ),\n plan,\n file,\n elapsedMs: Date.now() - startedAt,\n };\n }\n\n /*\n A destination whose last component is `.` or `..` does not name a directory of its own.\n\n `prepareOutputDir` claims the final component with a single non-recursive mkdir, having\n created its parents recursively — which is what makes two conversions racing for one\n directory safe. `path.dirname(\"out/.\")` is `\"out\"`, so for these the parent step creates\n the destination itself and the claim then asks the filesystem to make `.` inside it,\n which always exists. The result was a refusal naming a directory this same run had just\n made, one line after making it:\n\n edf2csv rec.edf --out ./fresh/.\n error: \"./fresh/.\" already exists.\n Pass --force to overwrite it, or --out to choose a different directory.\n\n Exit 1, nothing converted, and an empty `fresh/` left on disk. `--force` does not help:\n the claim fails the same way whatever it is told, so the path was unusable rather than\n occupied.\n\n Normalised only in that case, so `--out ./converted` keeps the spelling it was given —\n that one is already how the directory is found on disk, which is what `output_dir`\n promises, and rewriting it to `converted` would churn every example for no gain.\n */\n const asked = options.outputDir ?? defaultOutputDir(inputPath);\n const outputDir = /(?:^|[\\\\/])\\.\\.?$/u.test(asked) ? path.normalize(asked) : asked;\n await assertInputDoesNotOverlapOutputs(inputPath, outputDir, file, plan, options);\n await prepareOutputDir(outputDir, options.force === true);\n\n const written: WrittenFile[] = [];\n\n if (plan.writeSignals && plan.groups.length > 0) {\n const signals = await writeSignalFiles(file, plan, outputDir, timing.starts, options);\n written.push(...signals);\n } else {\n const missing = noSignalFile(file, plan);\n if (missing) plan.diagnostics.push(missing);\n }\n\n const noEvents = noAnnotations(file, options);\n if (noEvents) plan.diagnostics.push(noEvents);\n\n let annotationsWritten = 0;\n if (file.annotationSignals.length > 0) {\n const window = requestedAnnotationWindow(options, plan.range.recordingStartSeconds);\n // Reported against the rows that will be written, not against the file; see\n // durationDiagnostics.\n plan.diagnostics.push(\n ...durationDiagnostics(annotationData.annotations, window, plan.gzip),\n );\n plan.diagnostics.push(\n ...descriptionDiagnostics(annotationData.annotations, window, plan.gzip),\n );\n const result = await writeAnnotationsCsv(\n outputDir,\n annotationData.annotations,\n window,\n options.gzip === true,\n options.bom === true,\n );\n written.push(result);\n annotationsWritten = result.rows;\n /*\n A run whose only table came out empty, which nothing said.\n\n `emptyWindow`'s own docstring states the rule this was breaking: \"everywhere else that\n a request produces nothing this tool says so: a --channels term matching nothing is an\n error, and --annotations-only on a file with no events raises NO_ANNOTATIONS.\" The\n second half is true only of a file with no annotation *channel*. Give the flag a\n recording whose channel carries nothing but timekeeping, or a window its events fall\n outside, and the run writes an annotations.csv holding one header line, prints \"Wrote\n … annotations.csv 0 rows\", exits 0 and passes --strict — which is exactly the shape\n EMPTY_WINDOW exists to refuse on the signal side, arriving by the other route.\n\n Only when there is no signal table either, so this is the whole of what the run\n produced. A windowed conversion of a recording whose events sit elsewhere is\n ordinary and its signals are the point; warning there would fire on most windows of\n most annotated recordings, which is how a warning stops being read.\n */\n if (!plan.writeSignals && annotationsWritten === 0) {\n plan.diagnostics.push(emptyAnnotations(annotationData.annotations.length, window, plan.gzip));\n }\n }\n\n written.push(\n await writeChannelsCsv(outputDir, file, plan, options.gzip === true, options.bom === true),\n );\n\n /*\n The file moved under the conversion. Said out loud, because nothing else shows it.\n\n The CSVs are still correct for the records that were read, and metadata.json still\n describes the file as it was opened — so the record is consistent with the output\n whatever happens here. What stops being true is that the checksum describes the bytes\n that were converted, since an in-place overwrite leaves nowhere to read them from. It\n is dropped rather than guessed at.\n */\n const changed = await file.changedSinceOpen();\n if (changed) plan.diagnostics.push(inputChanged(options.checksum === true));\n\n await writeMetadata(\n outputDir,\n inputPath,\n file,\n plan,\n written,\n annotationsWritten,\n changed ? null : checksumAtOpen,\n timing.starts !== null,\n options.bom === true,\n );\n\n const stale = await findStaleOutput(outputDir, written);\n\n return {\n outputDir,\n files: written,\n readerHungUp: false,\n annotationCount: annotationsWritten,\n // The directory path needs it too: `--gzip` changes the names, and two of these\n // sentences are a file name and nothing else. See withSidecarsNamed.\n diagnostics: withSidecarsNamed(\n withSignalTableUnwritten(\n [\n ...withTimingPromiseKept(withoutFileRateWarning(file.diagnostics), timing.starts !== null),\n ...plan.diagnostics,\n ...stale,\n ],\n plan.writeSignals,\n plan.gzip,\n convertedChannels(plan),\n ),\n { toStdout: false, gzip: plan.gzip },\n ),\n plan,\n file,\n elapsedMs: Date.now() - startedAt,\n };\n } finally {\n await file.close();\n }\n}\n\n/*\n Files this tool produces, used to spot leftovers from an earlier conversion.\n\n The rate part has to allow every shape a filename can now take, not just the plain ones:\n\n signals_256hz.csv an integer rate\n signals_12_5hz.csv a fractional rate, decimal point written as an underscore\n signals_1_000e-7hz.csv a rate small enough to need exponent form (0.2.2)\n signals_256hz.csv.gz any of the above, compressed (0.3.0)\n signals_0hz_2.csv a second group whose rate slug collided (0.2.1)\n\n The previous `[\\w.]+hz` matched neither of the last two — `-` and `+` are not word\n characters, and the collision suffix falls after the `hz`. Both were introduced by\n recent changes and both silently stopped being recognised as this tool's own output, so\n leftovers of exactly those kinds went unreported: the one situation the warning exists\n for. Requiring a digit after the underscore keeps a user's own `signals_notes.csv` out.\n\n And `signals_Infinityhz.csv`, which is a name this tool writes and the digit rule then\n excluded. A record duration too small to divide into overflows the rate — `rateSlug` says\n `Infinityhz` and the writer opens that file, with the TIME_RESOLUTION warning beside it\n saying no rows will go in it — so a mixed-rate run of such a file leaves two `signals_*`\n files behind and the next conversion into that directory named one of them:\n\n warning: signals_1e+308hz.csv is left over from an earlier conversion into this\n directory and was not rewritten.\n\n with `signals_Infinityhz.csv` sitting beside it, from the same run, unmentioned. Spelled\n out rather than loosened, so a user's own `signals_notes.csv` stays out for the reason\n above; the check below holds the pattern against every name `rateSlug` can produce.\n*/\nconst OUTPUT_PATTERN =\n /^(signals(_(\\d[\\w.+-]*|Infinity)hz(_\\d+)?)?\\.csv(\\.gz)?|annotations\\.csv(\\.gz)?|channels\\.csv(\\.gz)?|metadata\\.json)$/u;\n\n/**\n * Detect output from a previous run that this one did not replace.\n *\n * `--force` overwrites files but does not empty the directory, so converting a\n * mixed-rate recording and then a single-rate one into the same place leaves\n * `signals_256hz.csv` sitting next to a fresh `signals.csv`. Both look current.\n * Nothing is deleted here — the user is told, and decides.\n */\nasync function findStaleOutput(\n outputDir: string,\n written: readonly WrittenFile[],\n): Promise<Diagnostic[]> {\n const entries = await readdir(outputDir).catch(() => null);\n if (!entries) return [];\n\n // metadata.json is rewritten on every run but is not part of the reported file list.\n const fresh = new Set([...written.map((f) => f.name), 'metadata.json']);\n const stale = entries.filter((name) => OUTPUT_PATTERN.test(name) && !fresh.has(name)).sort();\n if (stale.length === 0) return [];\n\n return [\n {\n code: 'STALE_OUTPUT',\n severity: 'warning',\n /*\n Through `listed`, like every other message that enumerates something this run does not\n control. How many stale files a directory holds is up to the directory, and a\n mixed-rate recording converted into a reused one is exactly how it fills up: 120 old\n `signals_<rate>hz.csv` files produced a single 2,373-character warning line. That is\n the failure `listed` was written for — its own comment quotes the 1,600-character\n version of it — and this was the one message still joining its own list.\n\n The hint said \"Delete them\" whatever the count, so one stale file read \"signals_999hz\n .csv is left over ... Delete them.\"\n */\n message:\n `${listed(stale)} ${stale.length === 1 ? 'is' : 'are'} left over from an earlier ` +\n `conversion into this directory and ${stale.length === 1 ? 'was' : 'were'} not rewritten.`,\n hint:\n `Delete ${stale.length === 1 ? 'it' : 'them'}, or convert into a fresh directory, so ` +\n 'the two runs do not get mixed up.',\n },\n ];\n}\n\nexport function defaultOutputDir(inputPath: string): string {\n /*\n The third export whose only argument is a path, and the one left handing a wrong value on.\n\n `path.basename` refuses a non-string with Node's own text — `The \"path\" argument must be\n of type string. Received type number (5)` — which names a parameter of `path`, not one of\n this function, and reaches a caller who never called `path`. `convert` got this check in\n 0.7.x and `EdfFile.open` in 0.8.9; this is what the api page tells you to call to find out\n where those two would write, so it is reached by exactly the same caller.\n */\n assertInputPath(inputPath);\n const base = path.basename(inputPath, path.extname(inputPath));\n return path.join(path.dirname(inputPath), `${base}_csv`);\n}\n\n/** Never let an output target resolve to the recording being read, even with --force. */\nasync function assertInputDoesNotOverlapOutputs(\n inputPath: string,\n outputDir: string,\n file: EdfFile,\n plan: ConversionPlan,\n options: ConvertOptions,\n): Promise<void> {\n /*\n The names this run will actually write, compressed ones included.\n\n The rate files come from the plan and already carry `.csv.gz` under --gzip; the sidecars\n were spelled out here and did not. So a compressed run checked two names it would never\n write and missed the two it would: a recording sitting at <outdir>/channels.csv.gz was\n overwritten by its own conversion, with --force, reported as a success. The same file\n named signals.csv.gz was refused, which is what gives the oversight away.\n */\n const suffix = options.gzip === true ? '.csv.gz' : '.csv';\n const names = new Set(plan.groups.map((group) => group.fileName));\n if (file.annotationSignals.length > 0) names.add(`annotations${suffix}`);\n names.add(`channels${suffix}`);\n names.add('metadata.json');\n\n const inputResolved = path.resolve(inputPath);\n /*\n Tolerant of the input going away, like every other stat in this function.\n\n This one was bare, so a recording renamed or unlinked between `EdfFile.open` and here threw\n Node's own error straight out of `convert()`:\n\n Error: ENOENT: no such file or directory, stat './link.edf'\n\n with no `code` this tool defines and no hint — a sixth error type from a function the API\n page says throws five, on the one path where a file moving under a conversion is the\n documented ordinary case. The descriptor is already open, so the conversion itself is fine;\n what is lost is the inode comparison, and `samePath` below still answers the case that\n matters when the two names are the same name.\n */\n const inputInfo = await stat(inputPath).catch(() => null);\n\n for (const name of names) {\n const target = path.join(outputDir, name);\n const targetResolved = path.resolve(target);\n const targetInfo = await stat(target).catch(() => null);\n const samePath = targetResolved === inputResolved;\n const sameFile =\n targetInfo !== null &&\n inputInfo !== null &&\n targetInfo.dev === inputInfo.dev &&\n targetInfo.ino === inputInfo.ino;\n if (!samePath && !sameFile) continue;\n\n throw new ConversionError(\n 'INPUT_OUTPUT_COLLISION',\n `Output file \"${target}\" is the same file as the input recording.`,\n 'Choose a separate directory with --out. The input was not modified.',\n );\n }\n}\n\nasync function prepareOutputDir(dir: string, force: boolean): Promise<void> {\n /*\n The destination, quoted into every refusal below, and shown rather than pasted.\n\n `--out` is whatever the caller's shell handed over, and `printableLines` escapes every\n control byte in a message except the one that makes a line break — it splits on those\n first, to keep the author's own lines. So a newline in a destination cut the refusal's\n first line in half:\n\n error: \"out/ex\n ists\" already exists.\n\n which is the line this tool's comments keep insisting stays whole, because it is the one a\n log gets grepped for. Same in `EdfFile.open`'s path and in a `--channels` term; all three\n go through `printable` now, where the summary and the report have always put them.\n */\n const shownDir = printable(dir);\n /*\n Claim the directory with a single atomic mkdir rather than asking whether it exists\n and then creating it.\n\n Checking first left a window between the two: two conversions started together both\n saw \"not there\", both proceeded, and both opened write streams on the same signals.csv.\n Neither reported anything — both exited 0, having half-written one file between them.\n A non-recursive mkdir cannot do that. Exactly one caller creates the directory; every\n other one gets EEXIST from the filesystem and takes the already-exists path below.\n\n Parents are still created recursively, since --out ./a/b/c should work. Only the final\n component is the claim.\n */\n const parent = path.dirname(dir);\n if (parent && parent !== dir) {\n try {\n await mkdir(parent, { recursive: true });\n } catch (cause: unknown) {\n // A parent that is a regular file surfaces as EEXIST naming the parent, which reads\n // as though the destination already exists rather than as \"you cannot put a\n // directory inside a file\". Name the real obstacle instead of the errno.\n const info = await stat(parent).catch(() => null);\n if (info && !info.isDirectory()) {\n throw new ConversionError(\n 'OUTPUT_UNWRITABLE',\n `Cannot create \"${shownDir}\": \"${printable(parent)}\" is a file, not a directory.`,\n 'Choose a destination whose parent directories are directories, with --out.',\n );\n }\n throw new ConversionError(\n 'OUTPUT_UNWRITABLE',\n `Cannot create \"${shownDir}\": ${describeFsError(cause)}.`,\n createHint(cause),\n );\n }\n }\n\n let claimed = true;\n try {\n await mkdir(dir);\n } catch (cause: unknown) {\n if ((cause as NodeJS.ErrnoException).code !== 'EEXIST') {\n throw new ConversionError(\n 'OUTPUT_UNWRITABLE',\n `Cannot create \"${shownDir}\": ${describeFsError(cause)}.`,\n createHint(cause),\n );\n }\n claimed = false;\n }\n\n if (!claimed) {\n const existing = await stat(dir).catch(() => null);\n\n // --force means \"replace my previous output\", not \"write output files into\n // whatever this happens to be\". Pointing it at a regular file needs saying so.\n if (existing && !existing.isDirectory()) {\n throw new ConversionError(\n 'OUTPUT_UNWRITABLE',\n `\"${shownDir}\" is a file, but the converted data needs a directory.`,\n 'Choose a directory with --out.',\n );\n }\n /*\n A link to nothing, which `stat` cannot see and `mkdir` will not write through.\n\n `stat` follows symbolic links, so a dangling one leaves `existing` null and fell through\n to the sentence below — which is the one claim that is not true of it:\n\n $ edf2csv rec.edf --out link-to-nowhere\n error: \"link-to-nowhere\" already exists.\n Pass --force to overwrite it, or --out to choose a different directory.\n\n Nothing is there. And following that advice made it worse: `--force` reached the writer\n and came back as `Writing to \"link-to-nowhere\" failed: part of the path does not exist.\n The files written so far are incomplete and should not be used` — a conversion failure,\n about files that were never written, advising the reader to make sure nothing is\n removing a directory that never existed.\n\n A broken link in a batch's destination is how this arrives: the run before it wrote into\n a mount that has since gone.\n */\n if (!existing && (await lstat(dir).catch(() => null))) {\n throw new ConversionError(\n 'OUTPUT_UNWRITABLE',\n `\"${shownDir}\" is a symbolic link to something that does not exist, so nothing can be ` +\n `written there.`,\n 'Remove the link, or choose a directory with --out. --force writes into a directory ' +\n 'that is already there, and a link to nowhere is not one.',\n );\n }\n if (!force) {\n /*\n What `--force` does, rather than what it sounds like it does.\n\n \"Overwrite it\" reads as a claim about the directory, and the neighbouring hint said so\n outright — \"--force replaces a previous output directory\". It does neither. It writes\n into the directory: files of the same name are replaced and everything else is left\n exactly where it was, which is why `STALE_OUTPUT` exists to report what stayed. The\n flag list has described it accurately since it was written — \"write into the output\n directory if it already exists\" — so the one sentence a reader meets at the moment\n they decide whether to pass it was the one contradicting the other two.\n\n The difference is a directory that ends up holding two conversions. Convert a\n mixed-rate recording and then a single-rate one into the same place with `--force`,\n and `signals_256hz.csv` sits beside a fresh `signals.csv` under a channels.csv and a\n metadata.json describing only the second — which is exactly the outcome a reader who\n was told the directory would be replaced does not expect, and does not check for.\n */\n throw new ConversionError(\n 'OUTPUT_EXISTS',\n `\"${shownDir}\" already exists.`,\n 'Pass --force to write into it, leaving whatever else it holds, or --out to choose ' +\n 'a different directory.',\n );\n }\n }\n}\n\n/**\n * Turn a Node filesystem error into something a person can act on: an errno as a sentence,\n * so Node's own text never reaches the screen.\n *\n * Exported for the CLI's last-resort stdout listener, which is the third and last place a\n * write failure becomes a message and the one that was still printing `ENOSPC: no space left\n * on device, write`.\n */\nexport function describeFsError(cause: unknown): string {\n const code = (cause as NodeJS.ErrnoException | undefined)?.code;\n if (code === 'EACCES' || code === 'EPERM') return 'permission denied';\n if (code === 'ENOSPC') return 'the disk is full';\n // The one that actually happens on a shared filesystem, and the one this list left out.\n if (code === 'EDQUOT') return 'you are over your disk quota on this filesystem';\n if (code === 'ENOTDIR') return 'part of the path is a file, not a directory';\n if (code === 'EROFS') return 'the filesystem is read-only';\n if (code === 'ENAMETOOLONG') return 'the path is too long';\n /*\n The two `writeHint` knew and this did not, which showed once the write failures started\n coming through here: `writeHint` reads the same errno off the same error and has a\n sentence for eleven of them, this had seven, and the gap was the two that only a write\n reaches. `EISDIR` is a directory sitting where an output file belongs, which is the\n commonest way to make one of these happen on purpose.\n\n `EPIPE` is deliberately not here. The writer treats a reader hanging up as the ordinary\n end of a pipeline rather than as a failure, so it never becomes a message.\n */\n if (code === 'EISDIR') return 'a directory is sitting there already';\n if (code === 'EMFILE' || code === 'ENFILE') return 'too many files are open';\n /*\n The one this list could not describe, and the recursive mkdir above is what makes it\n surprising: every parent is created on the way, so \"no such file or directory\" is not a\n parent that was missing. It is a component that exists and leads nowhere — a symbolic\n link with no target is the way to get one — or a directory removed by something else\n between the two calls.\n\n Missing it meant the fallback ran, which is Node's own text, complete with the internal\n call that raised it:\n\n error: Cannot create \"dangle/x\": ENOENT: no such file or directory, mkdir 'dangle'.\n Check the path exists and that you have permission to write there.\n\n Keeping that off the screen is the whole purpose of the six lines above it.\n */\n if (code === 'ENOENT') return 'part of the path does not exist';\n return cause instanceof Error ? cause.message : String(cause);\n}\n\nasync function writeSignalFiles(\n file: EdfFile,\n plan: ConversionPlan,\n outputDir: string | null,\n recordStarts: Float64Array | null,\n options: ConvertOptions,\n onHangUp?: (hungUp: boolean) => void,\n): Promise<WrittenFile[]> {\n // One budget for every table in this conversion, not one per table: see OffsetBudget.\n const offsets = newOffsetBudget();\n // Likewise one for every channel, not one per channel: see SampleCacheBudget.\n const sampleCaches = newSampleCacheBudget();\n // Only the stdout path needs this; --out finds a full disk on its own, because it always\n // has another file to write afterwards. See auditStdout.\n const audit = outputDir === null ? auditStdout() : null;\n /*\n In the long layout every group writes into one table, so they share one stream. Opening\n a stream per group on the same path is what the rate-slug collision fix in groupByRate\n was about: two writers on one file interleave rows under a header naming one of them.\n */\n let shared: {\n stream: Writable;\n settled: Promise<void>;\n release: () => void;\n target: Writable;\n writer: BufferedLineWriter;\n } | null = null;\n\n /*\n One buffer's worth of memory for the conversion, not one per table.\n\n Every group had its own writer at the default 1 MiB threshold, so pending output was\n group count × 1 MiB before anything drained. A 6.5 MB recording with 40 sampling rates\n — the header allows thousands of channels, and a research montage really does mix a\n dozen rates — died with a raw V8 heap out-of-memory and exit 134 under a 96 MB cap,\n while the site advertises 48 MB. The recording is small; it is the fan-out that is not.\n\n Split evenly with a floor, so the single-rate case, which is nearly every recording,\n keeps exactly the buffer it always had, and forty tables cost one megabyte between them\n rather than forty. The floor is what the sum is bounded by rather than the split: past\n 128 groups every table takes the 8 KiB minimum, so the total grows again from there.\n The long layout shares one writer already and is unaffected either way.\n */\n const MIN_FLUSH_THRESHOLD = 8 * 1024;\n const flushThreshold = Math.max(\n MIN_FLUSH_THRESHOLD,\n Math.floor(DEFAULT_FLUSH_THRESHOLD / Math.max(1, plan.groups.length)),\n );\n /*\n The stream's own buffer is the other half of the same sum.\n\n 0.5.6 shared the line-buffer budget and left `createWriteStream` at its 64 KiB default,\n which is per stream: 200 rate groups meant 12.8 MB of stream buffer on top of 12.8 MB of\n line buffer, and an 855 KB recording still died at a 48 MB cap. Shared the same way, with\n a floor that keeps an ordinary conversion writing in useful-sized pieces.\n */\n const streamBuffer = Math.max(\n 16 * 1024,\n Math.floor(DEFAULT_FLUSH_THRESHOLD / Math.max(1, plan.groups.length)),\n );\n\n const open: OpenGroup[] = plan.groups.map((group, groupIndex) => {\n // A null directory means the single table goes to stdout. process.stdout is already a\n // writable stream, so the same buffered writer and backpressure handling apply.\n const target =\n shared?.target ??\n (outputDir === null\n ? process.stdout\n : createWriteStream(path.join(outputDir, group.fileName), {\n highWaterMark: streamBuffer,\n }));\n const { stream, settled, release } = shared ?? compressed(target, options.gzip === true);\n /*\n Under --gzip the writer feeds the compressor, so its byte count is the CSV before\n compression and says nothing about what reached the descriptor. The compressor's own\n output is what stdout is handed, so that is what is counted. `pipe` uses a 'data'\n listener of its own and a second one is delivered the same chunks.\n\n Once per stream, which in the long layout is once for all the groups. Attaching per\n group put N listeners on the one shared compressor, so every chunk was counted N\n times: `--stdout --layout long --gzip` on a 40-rate recording claimed 622,240 of\n 622,240 bytes where 15,556 had been written, failed with a disk-full error over a\n perfectly good file, and printed Node's MaxListenersExceededWarning to stderr on the\n way past ten. 0.5.4 fixed the same arithmetic in the uncompressed branch and left\n this one, because the uncompressed branch is where the count is a sum and this one is\n where it is a subscription.\n */\n if (audit && stream !== target && !shared) {\n stream.on('data', (chunk: Buffer) => audit.count(chunk.length));\n }\n /*\n One writer, not one per group, when the table is shared. Separate writers over one\n stream each hold their own buffer and flush on their own schedule, so the rows would\n reach the file in whatever order the buffers filled — which is not the order they\n were produced in, and the long layout's whole claim is that its rows are in time\n order.\n */\n const writer = shared?.writer ?? new BufferedLineWriter(stream, flushThreshold);\n if (plan.layout === 'long' && !shared) shared = { stream, settled, release, target, writer };\n\n // Only the first group writes the header of a shared table, and the mark before it.\n if (plan.layout !== 'long' || groupIndex === 0) {\n if (options.bom === true) writer.push(UTF8_BOM);\n writer.pushLine(\n plan.layout === 'long'\n ? csvRow([TIME_COLUMN, 'channel', 'value'])\n : csvRow([TIME_COLUMN, ...group.channels.map((c) => c.column)]),\n );\n }\n return {\n group,\n writer,\n formatters: group.channels.map((c) => makeSampleFormatter(c.signal, c.decimals, sampleCaches)),\n formatTime: makeTimeFormatter(\n group.samplesPerRecord,\n group.rate,\n group.timeDecimals,\n offsets,\n ),\n rows: 0,\n settled,\n release,\n };\n });\n\n try {\n const written = await streamSignalRows(file, plan, open, recordStarts, options);\n\n /*\n Checked once everything has been flushed and ended, and not when the reader hung up.\n\n `--stdout | head -1` closes the pipe on purpose, which is a shell idiom rather than a\n failure. A pipe is not a regular file, so auditStdout declines it anyway — the second\n guard is here because the cost of getting this one wrong is reporting a failure for a\n command that worked.\n */\n if (audit) {\n // Uncompressed, the writer hands its bytes straight to the descriptor; compressed,\n // they were counted on the compressor's way out.\n if (options.gzip !== true) {\n /*\n Once per writer, not once per group. The long layout gives every group the same\n writer, so counting per group multiplied its byte total by the number of rates:\n `--stdout --layout long` on a three-rate recording handed over 32,043 bytes, was\n credited with 96,129, and failed with a disk-full error for a file that was\n complete on disk. It only showed with stdout redirected to a regular file, since\n that is the one case the audit applies to — which is the command the --layout\n documentation gives.\n */\n for (const writer of new Set(open.map((entry) => entry.writer))) {\n audit.count(writer.bytesOut);\n }\n }\n if (!open.some((entry) => entry.writer.hungUp)) audit.verify();\n }\n onHangUp?.(open.some((entry) => entry.writer.hungUp));\n return written;\n } catch (cause) {\n for (const entry of open) entry.writer.destroy();\n\n /*\n Reading and writing both fail through here, and both were reported as writing.\n\n A recording that shrinks mid-conversion — still being written by the acquisition\n software, say — raises the reader's own error, which names the record and says the\n file changed size while it was being read. That precise diagnosis was then filed under\n `Writing to \"<dir>\" failed` and given the hint about freeing disk space, which sends\n someone to look at the one part of the system that was working.\n\n The reader's message and its advice are kept; only the note about partial output is\n added, since that much is true of either failure.\n */\n // A ConversionError arrived already saying what went wrong — a callback that threw, say.\n // Wrapping it again turned \"the onProgress callback threw\" into `Writing to \"out\"\n // failed: the onProgress callback threw`, under a hint about checking the destination.\n if (cause instanceof ConversionError) throw cause;\n\n if (cause instanceof EdfError) {\n const where = outputDir === null ? 'stdout' : `\"${outputDir}\"`;\n throw new ConversionError(\n 'INPUT_UNREADABLE',\n cause.message,\n `${cause.hint ? `${cause.hint} ` : ''}What was written to ${where} before it failed is ` +\n `incomplete and should not be used.`,\n );\n }\n\n /*\n Through `describeFsError`, like the destination errors above, and not through Node's\n own text.\n\n That function exists to keep an errno and the internal call that raised it off the\n screen — its comment says so in as many words, quoting the leak it was written for:\n `Cannot create \"dangle/x\": ENOENT: no such file or directory, mkdir 'dangle'.` The\n write failures never joined it, so a directory sitting where signals.csv belongs read\n\n error: Writing to \"out\" failed: EISDIR: illegal operation on a directory, open 'out/signals.csv'\n\n with the errno token, the syscall, the path repeated, and no full stop — the one\n diagnostic shape this tool went back and fixed. The hint printed directly under it has\n always read the same errno and said \"A directory is sitting where that file belongs\",\n so the answer was in hand; it was the sentence above it that had not asked.\n */\n throw new ConversionError(\n 'WRITE_FAILED',\n `Writing to ${outputDir === null ? 'stdout' : `\"${outputDir}\"`} failed: ` +\n `${describeFsError(cause)}.`,\n writeHint(cause, outputDir === null),\n );\n }\n}\n\n/**\n * Whether two sample times are close enough that only rounding could separate them.\n *\n * A relative epsilon, because the gap between doubles grows with magnitude. Well below any\n * real sample interval — the finest a recording can declare is bounded by its record\n * duration and samples-per-record fields — and well above the one-ULP disagreement that two\n * exact divisions of the same instant produce.\n */\nfunction nearlyEqual(a: number, b: number): boolean {\n return Math.abs(a - b) <= Math.max(Math.abs(a), Math.abs(b)) * 1e-12;\n}\n\n/**\n * One record's samples in the long layout: `time_s,channel,value`, in time order.\n *\n * The groups are merged rather than written one after another. Every sample in a record\n * falls inside that record's span, so taking the earliest next sample across the groups\n * each time leaves the whole file sorted by `time_s` — which is the only thing that makes a\n * mixed-rate long table useful, since sorting 3 million rows afterwards is the reader's\n * problem and a large one.\n *\n * Ties go to the group with the higher rate, which is the order the groups are already in.\n * Within a sample time the channels come out in the order the file declares them.\n */\nasync function writeLongRecord(\n file: EdfFile,\n open: readonly OpenGroup[],\n batch: RecordBatch,\n recordInBatch: number,\n recordStart: number,\n range: ConversionPlan['range'],\n): Promise<void> {\n const writer = open[0]?.writer;\n if (!writer) return;\n\n const cursors = new Int32Array(open.length);\n /* Reused across sample times so a three-million-row conversion allocates one of these. */\n const due: { entry: OpenGroup; groupIndex: number; sample: number; channel: number }[] = [];\n\n for (;;) {\n let earliest = Infinity;\n let source = -1;\n let sourceSample = 0;\n for (let g = 0; g < open.length; g++) {\n const entry = open[g];\n if (!entry) continue;\n const sample = cursors[g] ?? 0;\n if (sample >= entry.group.samplesPerRecord) continue;\n const time = recordStart + sample / entry.group.rate;\n if (time < earliest) {\n earliest = time;\n source = g;\n sourceSample = sample;\n }\n }\n if (earliest === Infinity) return;\n\n /*\n Everything at this instant, in the order the file declares its channels.\n\n Groups are ordered by rate, largest first, because that is how the wide layout names\n its files. Emitting a tie group by group therefore ordered the channels by descending\n sampling rate — so a recording declaring `slow, medium, fast` wrote `fast, medium,\n slow`, while the documentation promised file order and channels.csv listed file order.\n Signal index is the file's own order, and the only one a reader can predict.\n\n \"At this instant\" is decided on the time as written, not on the double. `s / rate` for\n two channels at one moment need not give the same double: a 0.3 s record holding 12 and\n 4 samples makes 40 Hz and 13.333… Hz, and 9/40 is 0.22500000000000000555 while 3/13.333…\n is 0.22499999999999997780. Equality missed that, so those two rows fell out in numeric\n order — `slow` before `fast`, once, in the middle of a file that was otherwise right.\n\n Two rows are at one time exactly when they carry the same `time_s`, which is the only\n definition a reader of the CSV can apply. The numeric pre-filter keeps the common case\n to one comparison; formatting happens only for candidates already within a hair.\n */\n let earliestText: string | null = null;\n /*\n Formatted on the first near-tie and not before, which on a single-rate table is never.\n\n The group and sample that set `earliest` are captured above rather than searched for\n again, since the loop below advances cursors as it goes and a later search would be\n looking at a table that had already moved on.\n */\n const asWritten = (): string =>\n (earliestText ??= open[source]?.formatTime(recordStart, sourceSample) ?? '');\n due.length = 0;\n for (let g = 0; g < open.length; g++) {\n const entry = open[g];\n if (!entry) continue;\n const sample = cursors[g] ?? 0;\n if (sample >= entry.group.samplesPerRecord) continue;\n const time = recordStart + sample / entry.group.rate;\n if (time !== earliest) {\n // Far away in the ordinary case; only a near-tie is worth formatting.\n if (!nearlyEqual(time, earliest)) continue;\n if (entry.formatTime(recordStart, sample) !== asWritten()) continue;\n }\n cursors[g] = sample + 1;\n // Same window rule as the wide layout, with the same per-rate slack.\n if (\n !sampleTimeIsInRange(earliest, range.startSeconds, range.endSeconds, toleranceFor(entry.group.rate))\n ) {\n continue;\n }\n for (let c = 0; c < entry.group.channels.length; c++) {\n due.push({ entry, groupIndex: g, sample, channel: c });\n }\n }\n if (due.length === 0) continue;\n if (due.length > 1) {\n due.sort(\n (a, b) =>\n (a.entry.group.channels[a.channel]?.signal.index ?? 0) -\n (b.entry.group.channels[b.channel]?.signal.index ?? 0),\n );\n }\n\n for (const item of due) {\n const channel = item.entry.group.channels[item.channel];\n const format = item.entry.formatters[item.channel];\n if (!channel || !format) continue;\n if (writer.hungUp) return;\n writer.pushLine(\n `${item.entry.formatTime(recordStart, item.sample)},${escapeCsvField(channel.column)},` +\n `${format(file.sampleAt(batch, recordInBatch, channel.signal, item.sample))}`,\n );\n item.entry.rows++;\n // Flushed inside the record for the same reason the wide layout is; see there.\n if (writer.full) await writer.flush();\n }\n }\n}\n\nasync function streamSignalRows(\n file: EdfFile,\n plan: ConversionPlan,\n open: OpenGroup[],\n recordStarts: Float64Array | null,\n options: ConvertOptions,\n): Promise<WrittenFile[]> {\n const { startSeconds, endSeconds, startRecord, endRecord } = plan.range;\n const { recordDuration } = file.header;\n let recordsDone = 0;\n\n /*\n Every destination has hung up, so nothing formatted from here on could reach anyone.\n `--stdout | head -1` is the usual way to arrive here: the reader takes one line and\n closes the pipe while the conversion is still near the start of the recording.\n\n Stopping also makes the reported row count mean what it says — rows that reached the\n consumer, rather than rows the loop went on formatting into a discarded buffer.\n */\n const allHungUp = (): boolean => open.length > 0 && open.every((entry) => entry.writer.hungUp);\n\n for await (const batch of file.readRecords({ startRecord, endRecord })) {\n if (allHungUp()) break;\n for (let r = 0; r < batch.recordCount; r++) {\n if (allHungUp()) break;\n const index = batch.firstRecordIndex + r;\n const recordStart = recordStarts ? (recordStarts[index] ?? index * recordDuration) : index * recordDuration;\n\n if (plan.layout === 'long') {\n await writeLongRecord(file, open, batch, r, recordStart, plan.range);\n recordsDone++;\n continue;\n }\n\n for (const entry of open) {\n const { group, writer, formatters, formatTime } = entry;\n const { channels, rate } = group;\n // Slack that never reaches the next sample; see toleranceFor.\n const slack = toleranceFor(rate);\n\n for (let sample = 0; sample < group.samplesPerRecord; sample++) {\n const time = recordStart + sample / rate;\n if (!sampleTimeIsInRange(time, startSeconds, endSeconds, slack)) continue;\n\n let row = formatTime(recordStart, sample);\n for (let c = 0; c < channels.length; c++) {\n const channel = channels[c];\n const format = formatters[c];\n if (!channel || !format) continue;\n row += ',' + format(file.sampleAt(batch, r, channel.signal, sample));\n }\n if (writer.hungUp) break;\n writer.pushLine(row);\n entry.rows++;\n\n /*\n Flushed inside the record, not only at the end of one.\n\n The buffer was drained once per record, so the rows of a single record piled up\n with nothing emptying them — memory followed samples-per-record rather than the\n batch size the writer exists to hold to. One record of 16,000,000 samples died\n with a heap out of memory under a 256 MB cap, while the same 32 MB of samples\n split into 16,000 records converted to the same 283 MB CSV without trouble. The\n format allows either layout and says nothing about which to expect.\n\n `full` is a synchronous read of the pending size, so the twenty million rows that\n are not at a boundary cost a comparison rather than a microtask each.\n */\n if (writer.full) await writer.flush();\n }\n await writer.maybeFlush();\n }\n\n recordsDone++;\n }\n\n if (options.onProgress) {\n /*\n A caller's callback is the caller's, and its failures are not the destination's.\n\n This ran inside the same try that turns a stream failure into WRITE_FAILED, so a\n progress callback that threw came back as `Writing to \"out\" failed: caller bug`,\n advising the reader to check a destination that was working perfectly. It is the\n same misattribution the write hints had until 0.4.36, one layer up.\n\n The original is kept as `cause`, so the stack that actually matters survives, and\n the conversion still stops — the callback threw, and carrying on writing into a\n directory whose owner has just failed is not an improvement.\n */\n try {\n options.onProgress({\n recordsDone,\n recordsTotal: endRecord - startRecord,\n // Once per writer: the long layout's groups share one, so summing per group\n // reported a figure larger than the file being written.\n bytesWritten: [...new Set(open.map((entry) => entry.writer))].reduce(\n (sum, entry) => sum + entry.charsWritten,\n 0,\n ),\n });\n } catch (cause) {\n throw new ConversionError(\n 'CALLBACK_FAILED',\n `The onProgress callback threw: ${cause instanceof Error ? cause.message : String(cause)}`,\n 'This is the caller\\'s callback, not the recording or the destination. Whatever was ' +\n 'written before it threw is incomplete and should not be used.',\n { cause },\n );\n }\n }\n }\n\n const closed = new Set<BufferedLineWriter>();\n for (const entry of open) {\n if (closed.has(entry.writer)) continue;\n closed.add(entry.writer);\n try {\n await entry.writer.end();\n // With --gzip the writer's stream is the compressor, whose end callback fires when the\n // compressor is done rather than when the file behind it is. Awaiting only that would\n // report success with the tail of the file still in flight.\n await entry.settled;\n } finally {\n // In a finally for the reason 0.5.45 gives about the writer's own release: a\n // conversion that fails here still has to leave process.stdout as it found it, and a\n // failure is exactly when a caller goes on to convert something else.\n entry.release();\n }\n }\n\n // A shared table is one file, and its row count is every group's rows, not the first's.\n if (plan.layout === 'long') {\n const first = open[0];\n if (!first) return [];\n return [{ name: first.group.fileName, rows: open.reduce((sum, e) => sum + e.rows, 0) }];\n }\n return open.map((entry) => ({ name: entry.group.fileName, rows: entry.rows }));\n}\n\n/**\n * The stream rows are written to, plus a promise for the data reaching its destination.\n *\n * Compression sits between the writer and the file as a transform. Failures below it — a\n * full disk, an unwritable path — surface on the file stream, where nothing is listening,\n * so they are forwarded onto the compressor: that is the stream the writer watches, and\n * routing them there keeps one error path rather than two.\n */\nfunction compressed(\n target: Writable,\n gzip: boolean,\n): { stream: Writable; settled: Promise<void>; release: () => void } {\n if (!gzip) return { stream: target, settled: Promise.resolve(), release: (): void => {} };\n const compressor = createGzip();\n /*\n Removable, because one of the streams this can be handed outlives the conversion.\n\n 0.5.36 fixed exactly this leak for the writer's own listener: a library caller running\n twelve `toStdout` conversions left twelve 'error' listeners on `process.stdout` and got\n Node's MaxListenersExceededWarning on the eleventh. That fix is `BufferedLineWriter`'s\n `#release()`, and it cannot reach this one — under `gzip` the writer's stream is the\n compressor, and `process.stdout` is only ever the compressor's destination. So the same\n leak survived on the same stream, behind one extra flag, and the regression test written\n to catch it does not pass `gzip: true`.\n\n A file stream is a different matter and needs no release: it is created for this\n conversion and closed with it. The discipline is the writer's — release only from a\n stream this tool does not own.\n */\n const forward = (error: Error): void => {\n compressor.destroy(error);\n };\n target.on('error', forward);\n const release = (): void => {\n if (target === process.stdout || target === process.stderr) target.off('error', forward);\n };\n\n /*\n pipe() ends its destination when the source ends, and stdout must survive the\n conversion: the writer already refuses to close it, because a closed stdout breaks\n every later write in the process. Nothing waits on stdout either — it is not this\n tool's to finish.\n */\n const toStdout = target === process.stdout;\n compressor.pipe(target, { end: !toStdout });\n if (toStdout) {\n /*\n Waited on, even though stdout is not ours to end.\n\n This returned an already-resolved promise, so `await entry.settled` waited for nothing\n and the conversion declared itself finished while the compressor still held the tail of\n the stream. `--stdout --gzip` onto a destination that filled up therefore printed the\n ENOSPC *and then* \"Wrote 102,400 rows to stdout.\" — and exited 0, over a file 11,270\n bytes short whose gzip member has no trailer and will not decompress. Through `--out`,\n on the same volume with the same space, the identical failure is reported and exits 1.\n\n The byte audit could not see it either: it stats the descriptor as soon as the writers\n are done, which on this path is before the compressor has pushed its last chunks.\n\n `finished(compressor)` is the source side, not the destination — it resolves when the\n compressor has flushed everything into stdout, and it is stdout's own write that fails.\n That keeps `end: !toStdout` exactly as it was: nothing here closes stdout.\n */\n const flushed = finished(compressor).catch((error: unknown) => {\n /*\n EPIPE is not a failure here, and turning it into one is the trap this nearly fell\n into: `--stdout --gzip | head` is an ordinary thing to type, and the documented\n answer to it is \"Stopped: the reader closed the pipe after 52,507 of 102,400 rows\n had been written\", exit 0. Waiting on the compressor surfaced the EPIPE that the\n uncompressed path already routes through the writer's hang-up flag — the writer\n sees the same error, forwarded, and records it — so the wait has to let that one\n through and keep everything else.\n */\n if ((error as NodeJS.ErrnoException | null)?.code === 'EPIPE') return;\n throw error;\n });\n flushed.catch(() => {});\n return { stream: compressor, settled: flushed, release };\n }\n\n /*\n A failure under the compressor rejects both this promise and the writer's own end(),\n and end() is the one awaited first. Without a handler attached here that rejection\n belonged to nobody, and Node killed the process over it: `--gzip` into an unwritable\n path printed a raw EISDIR stack trace instead of the ordinary \"Writing to ... failed\"\n message and exit 1, which is what the same path does uncompressed.\n\n Attaching the handler is enough to make it handled. Awaiting `settled` downstream still\n reports the failure in the case where end() happened to succeed.\n */\n const settled = finished(target);\n settled.catch(() => {});\n return { stream: compressor, settled, release };\n}\n\n/**\n * Write one of the sidecar files, reporting a failure the way the signal writer does.\n *\n * These three used to call `writeFile` bare, so a failure escaped as whatever the\n * filesystem said — `EISDIR: illegal operation on a directory, open '...'` with no hint\n * and, more importantly, no mention that the signal files had already been written. The\n * conversion stopped half-done and the message gave no sign of it.\n */\nasync function writeOutputFile(\n outputDir: string,\n name: string,\n contents: string,\n gzip = false,\n bom = false,\n): Promise<void> {\n // metadata.json never gets one: JSON.parse rejects a leading U+FEFF, so a mark there\n // would break every reader of the file to help a spreadsheet that will not open it.\n if (bom) contents = UTF8_BOM + contents;\n try {\n // The sidecars are built in memory before being written, so compressing them in memory\n // costs nothing extra. Only the signal tables are large enough to need a stream.\n await writeFile(path.join(outputDir, name), gzip ? gzipSync(contents) : contents, gzip ? undefined : 'utf8');\n } catch (cause) {\n // The same as the signal tables above; see the note there.\n throw new ConversionError(\n 'WRITE_FAILED',\n `Writing \"${name}\" to \"${outputDir}\" failed: ${describeFsError(cause)}.`,\n writeHint(cause),\n );\n }\n}\n\nasync function writeChannelsCsv(\n outputDir: string,\n file: EdfFile,\n plan: ConversionPlan,\n gzip: boolean,\n bom: boolean,\n): Promise<WrittenFile> {\n const includedColumns = new Set(plan.groups.flatMap((g) => g.channels.map((c) => c.signal.index)));\n const fileFor = new Map<number, string>();\n for (const group of plan.groups) {\n for (const channel of group.channels) fileFor.set(channel.signal.index, group.fileName);\n }\n\n /*\n A rate rendered the way the file name beside it in the same row was rendered.\n\n `sampling_rate_hz` and `output_file` are two cells of one row about one rate, and they were\n written from different renderings of it — the cell from `String`, the name from\n `formatRates` over the whole set. They agree on every rate `String` prints plainly and part\n company on the ones it does not:\n\n a,0,a,uV,1e-19,100,...,signals_1_000e-19hz.csv,yes\n\n A reader joining that column against the files on disk finds `1e-19` naming\n `1_000e-19hz`, and `--info` printing a third thing again — except that `--info`'s RATE\n column is `1.000e-19 Hz`, which is the name's own form. channels.csv was the one surface\n rendering the rate for itself.\n\n Rendered together because that is how the names are: two rates a sixth decimal apart round\n to one string, and `formatRates` widens the whole set when they do, so a per-rate rendering\n would disagree with the names again on exactly those files.\n */\n const groupRates = plan.groups.map((group) => group.rate);\n const rateText = new Map<number, string>(\n formatRates(groupRates).map((text, i) => [groupRates[i] as number, text]),\n );\n\n const lines = [\n csvRow([\n 'column',\n 'signal_index',\n 'label',\n 'unit',\n 'sampling_rate_hz',\n 'samples_per_record',\n 'physical_min',\n 'physical_max',\n 'digital_min',\n 'digital_max',\n 'transducer',\n 'prefiltering',\n 'output_file',\n 'converted',\n ]),\n ];\n\n for (const signal of file.header.signals) {\n if (signal.isAnnotations) continue;\n const column = plan.columnNames.get(signal.index) ?? `signal_${signal.index}`;\n lines.push(\n csvRow([\n column,\n String(signal.index),\n signal.label,\n signal.physicalDimension,\n /*\n Plain decimal, at whatever magnitude the header declares.\n\n `String` switches to exponent notation below 1e-6 and above 1e21, which `plain`\n exists to undo — annotations.csv's two numeric columns were given it because \"an\n EDF+ TAL states its onset as ordinary decimal text, so a file saying `+0.0000001`\n came back as `1e-7` in a column whose every other cell is a plain decimal\", and\n `fixed` refuses the same form in signals.csv for the same reason: \"a reader parsing\n the column as decimal text has no reason to expect it.\" channels.csv was the third\n CSV and the one that kept it. A magnetometer calibrated to ±1e-16 T had its\n `physical_min` written `-1e-16` beside a `digital_min` of `-32768`, in the pair of\n columns this documentation points at for recovering the digital codes, over a\n signals.csv writing every one of those values out in full — and a channel calibrated\n to ±100 in the row above it, so the column held both notations at once.\n */\n // Nor the rate, which is rendered above against the names it has to match. Nor\n // samples_per_record, which is a count.\n rateText.get(signal.samplingRate) ?? formatRate(signal.samplingRate),\n String(signal.samplesPerRecord),\n plain(signal.physicalMin),\n plain(signal.physicalMax),\n plain(signal.digitalMin),\n plain(signal.digitalMax),\n signal.transducer,\n signal.prefiltering,\n fileFor.get(signal.index) ?? '',\n includedColumns.has(signal.index) ? 'yes' : 'no',\n ]),\n );\n }\n\n const name = outputCsvName('channels', gzip);\n await writeOutputFile(outputDir, name, lines.join('\\n') + '\\n', gzip, bom);\n return { name, rows: lines.length - 1 };\n}\n\n/*\n The bounds an annotation is filtered against: what the caller actually asked for, not the\n window that survived being clamped to the recording.\n\n Filtering by the resolved window meant an unbounded request still lost events. `--end 999h`\n on a three-second file clamps to 3, and `--start 0` gets its end from the recording, so\n both filtered to [0, 3) and dropped the markers at 3.0 and 3.5 that a bare invocation\n keeps — asking for more of a recording returned less of it.\n\n An end the caller did not give is unbounded, not \"the end of the data\": EDF+ lets an\n annotation sit past the last sample, which is exactly where an end-of-recording marker is.\n\n `--duration` is measured from wherever the conversion actually starts. Anchoring it at 0\n instead read the same absent `--start` two ways in two adjacent lines, and on a recording\n that does not begin at zero the two windows did not even overlap: an EDF+D file whose first\n record sits at 30 s converted its samples from [30, 35) while filtering annotations against\n (-inf, 5), so every event inside the converted window was dropped and `annotations.csv` came\n back empty. `resolveRange` has always defaulted the same missing start to the earliest\n record, which is where this now takes it from.\n*/\n/**\n * What the durations in the events that will actually be written look like.\n *\n * These two warnings were raised from the file-wide counts the decoder accumulates, while\n * `annotations.csv` is filtered to the requested window. A conversion of one second of a\n * recording therefore warned that \"1 annotation states a duration that is not a number, so\n * its duration_s cell is empty\" about an event two seconds outside it — naming a cell that is\n * not in the output — and `--strict` failed the run for it. There is no such value, no such\n * cell, and no such row.\n *\n * Taken from the events themselves, after the same filter the writer applies, so the count\n * and the sentence describe the same rows. An unreadable duration is carried on the event\n * because `duration: null` cannot say whether the file gave one; a negative duration needs no\n * flag, since the value is right there.\n */\nexport function durationDiagnostics(\n annotations: readonly Annotation[],\n window: { from: number; to: number },\n /*\n And the name the run writes that file under, which these sentences did not have.\n\n Both hints send the reader to `annotations.csv` to look at the rows they are about, and a\n `--gzip` run writes `annotations.csv.gz`. `emptyAnnotations` two functions down takes this\n for the same reason and has since 0.8.48 — \"`--info` named `annotations.csv` for a run that\n wrote `annotations.csv.gz`\" — and the four beside it were left naming a file that is not in\n the directory.\n */\n gzip = false,\n): Diagnostic[] {\n const written = annotations.filter((a) => a.onset >= window.from && a.onset < window.to);\n const eventsFile = outputCsvName('annotations', gzip);\n const diagnostics: Diagnostic[] = [];\n\n const negative = written.filter((a) => a.duration !== null && a.duration < 0).length;\n if (negative > 0) {\n const one = negative === 1;\n diagnostics.push({\n code: 'ANNOTATION_DECODE_FAILED',\n severity: 'warning',\n message:\n `${counted(negative, 'annotation')} state${one ? 's' : ''} a duration below zero, ` +\n `which is not a length of time.`,\n hint:\n `The value is written to ${eventsFile} as the file gave it. Adding it to onset_s ` +\n 'ends the event before it starts, so check these rows before using the durations.',\n });\n }\n\n const unreadable = written.filter((a) => a.durationUnreadable === true).length;\n if (unreadable > 0) {\n const one = unreadable === 1;\n diagnostics.push({\n code: 'ANNOTATION_DECODE_FAILED',\n severity: 'warning',\n message:\n `${counted(unreadable, 'annotation')} state${one ? 's' : ''} a duration that is ` +\n `not a number, so ${one ? 'its' : 'their'} duration_s cell is empty.`,\n hint:\n 'The onset and the description were read normally. An empty duration_s otherwise ' +\n 'means the file stated no duration, so these rows cannot be told apart from those.',\n });\n }\n\n return diagnostics;\n}\n\n/**\n * What the descriptions in the events that will actually be written look like.\n *\n * EDF's four free-text header fields have had two warnings about where they land since they\n * were written: `FORMULA_LABEL` for text a spreadsheet runs instead of reading, and\n * `NONPRINTABLE_LABEL` for bytes that drive a terminal. Both say the same thing about the\n * remedy — the text is written exactly as the file has it, because rewriting it would mean\n * the CSV no longer says what the recording says — and both exist so that the tool is not\n * silent about where it goes.\n *\n * `annotations.csv`'s `description` column is the same kind of text, out of the same file,\n * into the same spreadsheet, and nothing was said about it at all. An event described\n * `=HYPERLINK(\"http://…\",\"Sleep stage W\")` was written verbatim, exit 0, no warning, and\n * opens as a live link nobody in the reading chain wrote; one carrying `\\x1b[31m` turns the\n * terminal red on `cat annotations.csv`. It is the more likely of the two to happen by\n * accident, since a description is typed by a person at a scoring station while a channel\n * label is written once by the recorder.\n *\n * It is also the only free text in the output that can carry a character above U+00FF —\n * header text is decoded latin1, so every byte of it becomes a code point below U+0100, and\n * a bidirectional override cannot reach a label. It can reach a description, which is UTF-8.\n *\n * Counted rather than raised per event, unlike the header's four fields: a night's scoring is\n * thousands of events, and a warning each is not a report. The count is of the rows that\n * reach `annotations.csv`, after the same window filter the writer applies, for the reason\n * `durationDiagnostics` beside it gives.\n */\nexport function descriptionDiagnostics(\n annotations: readonly Annotation[],\n window: { from: number; to: number },\n /** The name the run writes the event list under; see `durationDiagnostics`. */\n gzip = false,\n): Diagnostic[] {\n const written = annotations.filter((a) => a.onset >= window.from && a.onset < window.to);\n const eventsFile = outputCsvName('annotations', gzip);\n const diagnostics: Diagnostic[] = [];\n\n const formulaic = written.filter((a) => startsFormula(a.text));\n if (formulaic.length > 0) {\n const one = formulaic.length === 1;\n const shown = [...new Set(formulaic.map((a) => a.text[0] as string))].join(', ');\n diagnostics.push({\n code: 'FORMULA_LABEL',\n severity: 'warning',\n message:\n `${counted(formulaic.length, 'annotation')} ${one ? 'has a description' : 'have descriptions'} ` +\n `starting with ${shown}, which Excel, LibreOffice and Google Sheets read as the start ` +\n `of a formula rather than as text.`,\n hint:\n `The text is written to ${eventsFile} exactly as the file has it, so the cell is ` +\n 'what the recording says. Open the CSV with pandas or R, or import it into the ' +\n 'spreadsheet as text, if you do not want it evaluated.',\n });\n }\n\n const marked = written.filter((a) => unprintableIn(a.text).length > 0);\n if (marked.length > 0) {\n const one = marked.length === 1;\n const shown = [...new Set(marked.flatMap((a) => unprintableIn(a.text)))]\n .map(escapeCharacter)\n .join(', ');\n diagnostics.push({\n code: 'NONPRINTABLE_LABEL',\n severity: 'warning',\n message:\n `${counted(marked.length, 'annotation')} ${one ? 'has a description' : 'have descriptions'} ` +\n `carrying text a terminal does not print as itself (${shown}), written to ` +\n `${eventsFile} exactly as the file has ${one ? 'it' : 'them'}.`,\n hint:\n 'A control byte can drive the terminal and a bidirectional override reverses what ' +\n 'follows it, so read the file with pandas or R rather than with cat. The cell is ' +\n 'what the recording says either way.',\n });\n }\n\n return diagnostics;\n}\n\n/**\n * The window annotations are filtered by — the bounds as asked for, not as snapped to records.\n *\n * Exported so `--info` can count the events a conversion would write using the same predicate\n * that writes them, rather than a second copy of it.\n */\nexport function requestedAnnotationWindow(\n options: ConvertOptions,\n recordingStart: number,\n): { from: number; to: number } {\n const from = options.start ?? -Infinity;\n const to =\n options.end !== undefined\n ? options.end\n : options.duration !== undefined\n ? (options.start ?? recordingStart) + options.duration\n : Infinity;\n return { from, to };\n}\n\nasync function writeAnnotationsCsv(\n outputDir: string,\n annotations: readonly Annotation[],\n window: { from: number; to: number },\n gzip: boolean,\n bom: boolean,\n): Promise<WrittenFile> {\n const inWindow = annotations\n .filter((a) => a.onset >= window.from && a.onset < window.to)\n .sort((a, b) => a.onset - b.onset || a.recordIndex - b.recordIndex);\n\n const lines = [csvRow(['onset_s', 'duration_s', 'description', 'record_index'])];\n for (const annotation of inWindow) {\n lines.push(\n csvRow([\n plain(annotation.onset),\n annotation.duration === null ? '' : plain(annotation.duration),\n annotation.text,\n String(annotation.recordIndex),\n ]),\n );\n }\n\n const name = outputCsvName('annotations', gzip);\n await writeOutputFile(outputDir, name, lines.join('\\n') + '\\n', gzip, bom);\n return { name, rows: inWindow.length };\n}\n\n/**\n * What to try next, chosen from what actually went wrong.\n *\n * Every write failure carried the same advice — \"Free up space or choose another destination\n * with --out\" — which fits exactly one errno. A directory sitting where signals.csv belongs\n * came back telling the reader to free up disk space, and so did a read-only volume, a\n * permission denial and a path too long for the filesystem. Wrong advice is worse than none:\n * it sends someone to check `df` on a disk that is fine, and the thing that is actually\n * wrong stays unexamined.\n *\n * The errno is the one piece of the failure that names the cause, so it is what picks the\n * sentence. Anything unrecognised keeps the general form rather than guessing.\n */\nfunction writeHint(cause: unknown, toStdout = false): string {\n /*\n The stdout path writes no files, and --out is the flag its user chose not to pass.\n\n Both halves of this sentence were wrong there: \"the files written so far\" named files\n that do not exist, and \"choose another destination with --out\" is advice for a different\n command — the destination is whatever the shell redirected the stream to. Same class as\n the disk-space hint this function replaced, one flag over.\n */\n const preamble = toStdout\n ? 'What reached stdout before it failed is incomplete and should not be used. '\n : 'The files written so far are incomplete and should not be used. ';\n return (\n preamble +\n destinationAdvice(\n cause,\n toStdout ? 'redirect it somewhere else' : 'choose another with --out',\n toStdout ? 'redirect it somewhere shorter' : 'choose a shorter destination with --out',\n 'Part of that path no longer exists; make sure nothing is removing it while the ' +\n 'conversion runs.',\n )\n );\n}\n\n/**\n * The same question asked before anything has been written: the output directory could not be\n * created.\n *\n * Both raisings carried one sentence for every errno — \"Check the path exists and that you\n * have permission to write there\" — which is the shape `writeHint` above was written to\n * replace, in the words of its own docstring: \"Wrong advice is worse than none: it sends\n * someone to check `df` on a disk that is fine, and the thing that is actually wrong stays\n * unexamined.\" A full disk, a read-only volume and a path past the filesystem's length limit\n * all got advice about a path that exists and a permission that is not the problem, two lines\n * under a message where `describeFsError` had already named the cause exactly.\n *\n * No preamble, because nothing has been written yet — which is the only thing that differs\n * between the two, so the sentences themselves are shared rather than copied.\n */\nfunction createHint(cause: unknown): string {\n return destinationAdvice(\n cause,\n 'choose another with --out',\n 'choose a shorter destination with --out',\n 'Part of that path cannot be created — a symbolic link with nothing behind it, or a ' +\n 'mount point that is not mounted; choose another with --out.',\n );\n}\n\n/** The sentence an errno earns, with the two phrases that name where \"somewhere else\" is. */\nfunction destinationAdvice(\n cause: unknown,\n elsewhere: string,\n shorter: string,\n missing: string,\n): string {\n const code = (cause as NodeJS.ErrnoException | null)?.code;\n switch (code) {\n case 'ENOSPC':\n return `The destination is out of space; free some up or ${elsewhere}.`;\n case 'EDQUOT':\n return `You are over your disk quota on this filesystem; ${elsewhere}.`;\n case 'EACCES':\n case 'EPERM':\n return `You do not have permission to write there; ${elsewhere}.`;\n case 'EROFS':\n return `That filesystem is mounted read-only; ${elsewhere}.`;\n case 'EISDIR':\n return `A directory is sitting where that file belongs; remove or rename it, or ${elsewhere}.`;\n /*\n The one errno whose sentence is not the same question at both call sites.\n\n Mid-conversion, a missing component is a directory that went away under a run that had\n already written into it, and \"make sure nothing is removing it\" is the thing to check.\n Before anything is written it is the opposite: the destination's parents are created\n recursively, so reaching ENOENT there means a component that cannot be created — a\n symbolic link with nothing behind it, or a mount point that is not mounted.\n\n $ edf2csv rec.edf --out /mnt/archive/out\n error: Cannot create \"/mnt/archive/out\": part of the path does not exist.\n Part of that path no longer exists; make sure nothing is removing it\n while the conversion runs.\n\n Nothing is removing it and nothing was there. `createHint`'s own docstring says the\n preamble \"is the only thing that differs between the two, so the sentences themselves\n are shared rather than copied\" — and this is the sentence where that was not so.\n */\n case 'ENOENT':\n return missing;\n case 'ENAMETOOLONG':\n return `That path is longer than the filesystem allows; ${shorter}.`;\n case 'EMFILE':\n case 'ENFILE':\n return `Too many files are open; a recording with many sampling rates opens one output file per rate, so --channels narrows it.`;\n case 'EPIPE':\n return 'Whatever was reading the output closed it before the conversion finished.';\n default:\n return 'Check the destination and run the conversion again.';\n }\n}\n\n/**\n * Confirms that everything handed to a file-backed stdout actually arrived.\n *\n * `edf2csv rec.edf --stdout > out.csv` onto a volume that the output very nearly fills lost\n * the tail in silence: 94,977 of 102,400 rows on disk, the file ending mid-row, stderr\n * announcing \"Wrote 102,400 rows to stdout.\" and the process exiting 0. The same recording\n * onto the same volume through `--out` fails correctly, which is what gives it away.\n *\n * POSIX `write` returns a short count rather than an error when the disk fills partway\n * through a single call, and only the NEXT write raises ENOSPC. `--out` always has a next\n * write — channels.csv and metadata.json come after — so it always finds out. `--stdout`\n * has nothing after it, and when fd 1 is a regular file Node's stdout is a SyncWriteStream\n * whose `_write` discards the byte count `writeSync` returns, so nothing is raised at all.\n * No error means no `#failure`, so checking that alone would not have caught this.\n *\n * What can be checked is the descriptor: how much it grew against how much it was given.\n * Only for a regular file — a pipe, a terminal or a socket has no size to compare, and on\n * those a short write cannot go unreported this way. Appending (`>>`) is fine, since the\n * starting size is taken before anything is written.\n *\n * Exported so `--info` can use the same audit a `--stdout` conversion does.\n *\n * `--info` wrote its description with `process.stdout.write` and looked at nothing: redirected\n * into a full filesystem it produced a zero-byte file and exited 0, so `edf2csv rec.edf --info\n * > desc.txt` reported success over nothing at all. A 900-channel recording's description is\n * 58 KB, which is not a size a destination is guaranteed to have.\n */\nexport function auditStdout(): { count: (bytes: number) => void; verify: () => void } | null {\n let startSize: number;\n try {\n const info = fstatSync(1);\n if (!info.isFile()) return null;\n startSize = info.size;\n } catch {\n // No usable descriptor to audit; the conversion is not the place to complain about it.\n return null;\n }\n\n let expected = 0;\n return {\n count: (bytes: number): void => {\n expected += bytes;\n },\n verify: (): void => {\n let landed: number;\n try {\n landed = fstatSync(1).size - startSize;\n } catch {\n return;\n }\n if (landed >= expected) return;\n\n /*\n This audit exists for the failure nothing else reports: a write that is accepted, and\n silently truncated. When the stream itself raised an error there is nothing left for\n it to add, and what it added was a second `error:` line denying the first —\n\n error: Writing to stdout failed: ENOSPC: no space left on device, write\n error: Writing to stdout failed: 58900 of 58900 bytes did not reach the destination,\n which stopped accepting them part way through.\n ... nothing after it raised an error because there was nothing after it.\n\n one failure, reported twice, the second of the two wrong about it.\n */\n if (process.stdout.errored) return;\n\n /*\n Nothing landing at all is not a short write, and was described as one.\n\n `--info > desc.txt` onto a full filesystem left a zero-byte file, and this said the\n destination \"stopped accepting them part way through\" and that \"what is there ends\n mid-row\" — of a file with nothing in it and no rows in it.\n */\n if (landed === 0) {\n throw new ConversionError(\n 'WRITE_FAILED',\n `Writing to stdout failed: none of the ${counted(expected, 'byte')} reached the destination.`,\n 'The destination is almost certainly out of space. Nothing was written, so there ' +\n 'is nothing there to discard.',\n );\n }\n throw new ConversionError(\n 'WRITE_FAILED',\n // The pair a reader subtracts by eye, so both go through the grouping — the rule\n // 0.8.5 set and reached only as far as the messages already built with `counted`.\n `Writing to stdout failed: ${grouped(expected - landed)} of ` +\n `${counted(expected, 'byte')} did not reach the destination, which stopped ` +\n `accepting them part way through.`,\n 'What is there ends mid-row and should not be used. The destination is almost ' +\n 'certainly out of space — a short write is how a filesystem reports filling up ' +\n 'mid-write, and nothing after it raised an error because there was nothing after it.',\n );\n },\n };\n}\n\n/**\n * Why `--stdout` cannot take this recording, or null when it can.\n *\n * Lifted out of the conversion so `--info` can ask the same question. It was not asking:\n * `--info --stdout` on a three-rate recording predicted \"Would write 1,155 rows, roughly\n * 22.2 KB\" and said the channels \"are written to one file per rate\" — for a command that\n * refuses to run, writes nothing, and names no files. `--info` exists to say what a\n * conversion will do, and this is one of the things it does.\n *\n * Reported by `--info` as a warning rather than a refusal, for the reason 0.5.51 gives about\n * the destination guards: `--info` writes nothing, so a rule about what the output would be\n * has no business stopping it from describing the recording — and being told the command\n * will not work is exactly what you asked.\n */\nexport function stdoutRefusal(file: EdfFile, plan: ConversionPlan): ConversionError | null {\n if (!plan.writeSignals) {\n return new ConversionError(\n 'UNSUPPORTED_REQUEST',\n '--stdout has no signal data to write because --annotations-only was given.',\n 'Drop one of the two flags.',\n );\n }\n\n /*\n No table at all is its own answer, and neither layout gave it.\n\n A recording with no signal channels — one holding only EDF+ annotations — produced\n zero rate groups. The wide layout then said \"--stdout needs exactly one table, but\n this recording produces 0, one for each sampling rate its channels use ()\", with an\n empty parenthetical, advice to narrow to one of no rates, and advice to use\n `--layout long` — which wrote zero bytes to stdout, not even a header row, and exited\n 0 while warning that \"the signal files hold their headers and no data\". There were no\n files and there was no header. The one path that was right about this is\n `--annotations-only`, which refuses outright, and this is the same situation reached\n by a different route.\n */\n if (plan.groups.length === 0) {\n return new ConversionError(\n 'UNSUPPORTED_REQUEST',\n file.dataSignals.length === 0\n ? `--stdout has no signal data to write: this recording has no signal channels, ` +\n `only ${file.header.isBdf ? 'BDF+' : 'EDF+'} annotations.`\n : '--stdout has no signal data to write: nothing was selected that carries samples.',\n file.dataSignals.length === 0\n ? /*\n Named the way that conversion would name it, since `--gzip` is already on the\n command line this is refusing. This hint is nothing but a command to run, and the\n command it names writes `annotations.csv.gz` — so a reader who follows it finds\n nothing under the name they were given. Same fault 0.8.48 fixed for the warnings,\n in the one refusal that names a file.\n */\n `Convert to a directory to get its ${outputCsvName('annotations', plan.gzip)}, or ` +\n `drop --stdout.`\n : 'Check --channels and the requested window, or convert to a directory instead.',\n );\n }\n\n // The long layout is one table whatever the rates are, so it has nothing to refuse.\n if (plan.layout !== 'long' && plan.groups.length !== 1) {\n return new ConversionError(\n 'UNSUPPORTED_REQUEST',\n // Naming the rates is the point: the hint says to narrow the selection, and this\n // is what there is to narrow it to. The parenthetical used to repeat the count\n // that had just been given — \"produces 3 (its channels use 3 different sampling\n // rates)\" — which told nobody anything they could act on.\n `--stdout needs exactly one table, but this recording produces ${grouped(plan.groups.length)}, ` +\n `one for each sampling rate its channels use ` +\n `(${listed(formatRates(plan.groups.map((g) => g.rate)).map((r) => `${r} Hz`))}).`,\n 'Narrow it to one rate with --channels, write --layout long to get them all in ' +\n 'one table, or convert to a directory instead.',\n );\n }\n return null;\n}\n\n\n\n/**\n * Asked for signal data and given none to put in a file.\n *\n * Every channel selected carries zero samples per record, so there is no table to make —\n * `edf2csv rec.edf --channels unused` writes channels.csv and metadata.json and no signals.csv\n * at all. The NO_SAMPLES warning explains the channel; nothing explained the missing file, and\n * the documentation says signals.csv is written unless --annotations-only was passed. Someone\n * looking for it should be told where it went.\n *\n * There are two ways to arrive with no groups, and one wording is only true of one of them. A\n * recording that holds nothing but EDF+ annotations has no channel that could have been\n * selected, its channels.csv is a header row and nothing else, and no channel of it carries\n * samples — so \"every channel selected\", \"channels.csv still describes them\" and \"which\n * channels do carry samples\" were three false statements in one warning, printed under a\n * warning that had just said the file has no signal channels.\n *\n * Exported, and worded in the present tense, so `--info` can raise the same one. It was built\n * inline here, which meant the one mode whose purpose is to say what a conversion will do said\n * nothing about the file that conversion would not write: `--info --strict` on a recording of\n * nothing but annotations reported one warning where converting it reported two, and\n * `--info --json` carried the shorter list to whatever reads it. Everything the answer depends\n * on is in the file and the plan, both of which `--info` already has.\n */\nexport function noSignalFile(file: EdfFile, plan: ConversionPlan): Diagnostic | null {\n if (!plan.writeSignals || plan.groups.length > 0) return null;\n const noChannelsAtAll = file.dataSignals.length === 0;\n return {\n code: 'NO_SAMPLES',\n severity: 'warning',\n message: noChannelsAtAll\n ? 'No signal file is written: there is no signal data in this recording to put in one.'\n : 'No signal file is written: every channel selected carries zero samples per data ' +\n 'record, so there is nothing to put in one.',\n // Named as they will be written. `plan.gzip` is on the plan because `--info` named\n // `annotations.csv` for a run that wrote `annotations.csv.gz`; these two sentences are\n // about the same pair of files and were still naming the uncompressed ones.\n hint: noChannelsAtAll\n ? `${outputCsvName('annotations', plan.gzip)} holds whatever events it carries. ` +\n `${outputCsvName('channels', plan.gzip)} lists signal channels, so it has none to list.`\n : // `--info` raises this too, since 0.7.84, and was told to run itself to answer it.\n // Naming where the number lives works in both modes; naming a command works in one.\n 'Nothing about them is lost: every channel\\'s samples per record is in the channel ' +\n `table --info prints, and in the ${outputCsvName('channels', plan.gzip)} a conversion writes.`,\n };\n}\n\n/**\n * The channels whose samples this run actually writes.\n *\n * `plan.columnNames` names every channel of the recording, because the names are derived from\n * the whole file rather than from the selection — so it is not the answer. The groups are:\n * `--channels` builds them out of what was selected, and a channel with no samples per record\n * has none to put in one either.\n */\nexport function convertedChannels(plan: ConversionPlan): Set<number> {\n return new Set(plan.groups.flatMap((group) => group.channels.map((c) => c.signal.index)));\n}\n\n/**\n * The signal table an `--annotations-only` run does not write, taken out of the hints about it.\n *\n * That mode writes the event list and nothing else — no signal files at all — and four hints\n * about record timing describe the rows of one. On a recording whose records run backwards it\n * printed both of these over an annotations.csv holding its header and no rows:\n *\n * warning: This is a discontinuous (EDF+D) recording: its data records are not\n * contiguous in time.\n * Each row carries its true recording time, so gaps stay visible instead of\n * being closed.\n * warning: 2 data records start earlier than the record before them.\n * Rows are written in file order, so the time column will not increase\n * monotonically.\n *\n * There are no rows and no time column. The facts above the hints are about the recording and\n * stay; what changes is the sentence describing what the conversion will do with them, which\n * is the same surgery `withTimingPromiseKept` does to the first of these when the record\n * starts cannot be derived.\n *\n * `writesSignals` rather than the option, because the plan is what settles it.\n */\nexport function withSignalTableUnwritten(\n diagnostics: readonly Diagnostic[],\n writesSignals: boolean,\n gzip: boolean,\n /*\n And the channels this run leaves out, which is the same question one channel at a time.\n\n `--annotations-only` writes no cells for any channel; `--channels` writes none for the\n ones it excludes, and the five sentences below are as untrue of those as they are of the\n whole run. `--info` prints `(not selected)` in the OUTPUT column for them and channels.csv\n records them with `converted: no`, and the warning three lines under the table said:\n\n 0 flat flat uV 4 Hz 0 to 0 (not selected)\n ...\n warning: Signal 0 (\"flat\") has digital minimum equal to digital maximum (0), so its\n values cannot be scaled.\n Its cells are left empty rather than filled with a value the header cannot\n justify.\n\n There are no cells. Under `--strict` that is a failed run over a channel this one does not\n touch. The rewrites are the same rewrites, so the set of them is the argument rather than\n a second copy: empty means no signal table at all, which is what `writesSignals` said.\n */\n converted: ReadonlySet<number> = new Set(),\n /*\n And whether this run writes the file those rewrites send the reader to.\n\n Every sentence below that takes a cell away offers channels.csv in its place — \"channels.csv\n still records the digital range the header gives\", \"it is named `signal_1` in channels.csv's\n column cell\". `--stdout` writes no sidecar at all, and it can be given `--channels`:\n\n $ edf2csv rec.edf --stdout --channels ECG > rows.csv\n warning: Signal 0 (\"flat\") has digital minimum equal to digital maximum (0), so its\n values cannot be scaled.\n No samples are converted for a channel --channels left out, so there are no\n cells to leave empty. channels.csv still records the digital range the\n header gives.\n\n It does not. The run writes one CSV to the stream and nothing else, so the file offered\n as the place the channel is still described is not written either — which is the same\n thing `withSidecarsNamed` says one pass later about the sentences it knows. These are the\n ones it has never been shown: they do not exist until this pass writes them.\n */\n toStdout = false,\n): Diagnostic[] {\n const skipped = (diagnostic: Diagnostic): boolean => {\n if (!writesSignals) return true;\n const named = /^Signal (\\d+)\\b/u.exec(diagnostic.message);\n return named !== null && !converted.has(Number(named[1]));\n };\n if (writesSignals && diagnostics.every((d) => !skipped(d))) return [...diagnostics];\n /*\n The sidecars named here are named as the run writes them.\n\n These sentences send the reader to the one file an `--annotations-only` run does write, and\n said `channels.csv` to a `--gzip` run that writes `channels.csv.gz` — five hints pointing at\n a name that is not in the directory, one of them beside the `_ch` collision hint that 0.8.48\n had already taught to say `channels.csv.gz`. So a single run named both spellings, and only\n the second one existed.\n */\n /*\n Named plainly under `--stdout`, where no compressed sidecar is written either.\n\n `--stdout --gzip` compresses the stream and nothing else, so `channels.csv.gz` is as\n absent as `channels.csv` — and it is the spelling `withSidecarsNamed` already uses one\n pass later when it says none is written.\n */\n const channelsFile = outputCsvName('channels', gzip && !toStdout);\n const annotationsFile = outputCsvName('annotations', gzip);\n /*\n What channels.csv still holds about the channel, or that there is no channels.csv.\n\n Worded the way the sidecar pass words the hints it rewrites — the file is named, so the\n reader knows what they are missing, and the command that produces it is named too.\n */\n const records = (what: string): string =>\n toStdout\n ? `--stdout writes no ${channelsFile}; a conversion to a directory records ${what}.`\n : `${channelsFile} still records ${what}.`;\n return diagnostics.map((diagnostic) => {\n if (!skipped(diagnostic)) return diagnostic;\n // The reason the cells are missing, which is the only part that differs between the two.\n const because = writesSignals ? 'for a channel --channels left out' : 'with --annotations-only';\n // The run-level sentences below are only reached when no signal table is written at all:\n // a selection leaves the rows alone, so nothing it excludes changes what the column says.\n const writes = '--annotations-only writes no signal rows';\n\n /*\n And the three calibration warnings, whose hints are about cells.\n\n Each describes what a conversion does with a channel whose header cannot map cleanly —\n leaves the cell empty, fills it with the one value the mapping has, keeps the inversion —\n and `--annotations-only` converts no samples, so none of it happens:\n\n warning: Signal 0 (\"flat\") has digital minimum equal to digital maximum (0), so its\n values cannot be scaled.\n Its cells are left empty rather than filled with a value the header cannot\n justify.\n\n What is wrong with the header is still worth saying, and channels.csv — which that run\n does write — still carries the calibration. One message also ends in the conversion:\n \"so every sample converts to the same value\", over a run converting none.\n */\n /*\n And the two that say where a channel's name lands, which is signals.csv in both layouts\n and neither of them here.\n\n `--annotations-only` writes no signal table at all, so the name reaches exactly one\n place: channels.csv's `column` cell, which that run does write — control bytes, `_ch`\n suffix and all. Both sentences sent the reader to a file that is not there:\n\n warning: Signal 0's label and unit contain 2 control characters (\\x1b), which will\n appear as the channel's name in signals.csv and in channels.csv's unit\n cell in any conversion that writes one ...\n warning: 2 signals share the label \"T8-P8\" (positions #0, #1).\n Their names are suffixed with the signal number so they stay\n distinguishable: a column name each in the wide layout, and a distinct\n value in the channel column under --layout long.\n\n Neither layout happens. The second sentence offers a choice between two files that are\n not written.\n */\n if (diagnostic.code === 'NONPRINTABLE_LABEL') {\n return {\n ...diagnostic,\n message: diagnostic.message\n /*\n The hedge goes where the file goes, so it is taken off wherever the header put it\n and folded into the clause below. A run writing into a directory does write\n channels.csv, and the qualification is noise there; a `--stdout` run writes none,\n which is the case the header's own sentence has been qualified for since 0.8.52.\n */\n .replace(' in any conversion that writes one', '')\n .replace(\n \"as the channel's name in signals.csv\",\n `as the channel's name in ${channelsFile}'s column cell` +\n `${toStdout ? ' in any conversion that writes one' : ''}`,\n )\n // Matched on the name the header diagnostic used, which the line above has not\n // touched: it renames the first mention, and this collapses the second.\n .replace(\"and in channels.csv's\", 'and in its'),\n };\n }\n /*\n And the channel that lost its own name, whose sentence ends in a column.\n\n plan.ts writes \"so its column is `X`\" for a run that writes a signal table and \"so it is\n named `X` in channels.csv's column cell\" for one that does not — decided by the run,\n because that is all it knows there. A selection decides it per channel: the rename still\n happens, since the names are derived from the whole file so that they agree with\n channels.csv and across runs, and the column it is named for is one this run has not got.\n */\n if (diagnostic.code === 'DUPLICATE_LABEL' && / so its column is \"/u.test(diagnostic.message)) {\n return {\n ...diagnostic,\n message: diagnostic.message.replace(\n / so its column is (\"[^\"]*\")\\.$/u,\n ` so it is named $1 in ${channelsFile}'s column cell` +\n `${toStdout ? ' in any conversion that writes one' : ''}.`,\n ),\n };\n }\n /*\n And the same sentence when the plan wrote it in this form to begin with.\n\n plan.ts decides between three nouns from the options it has — a column, the channel\n column of a long table, or a cell of channels.csv when no signal table is written at\n all — so under `--annotations-only` the sentence arrives already naming the cell, and\n the rewrite above, which matches the wide-layout form, never sees it. Which left the\n one form this pass could not touch as the one form carrying neither of the two things\n it knows: the hedge, and what `--stdout` calls that file.\n\n $ edf2csv montage.edf --info --stdout --gzip --annotations-only\n warning: Signal 2 is labelled \"T8_ch0\", ... so it is named \"T8_ch0_ch2\" in\n channels.csv.gz's column cell.\n Channel names are unique, and --stdout writes no channels.csv to look\n this channel up in by its signal_index — convert to a directory for that.\n\n One warning, one file, two spellings of it, and neither written by that run.\n */\n if (diagnostic.code === 'DUPLICATE_LABEL' && /'s column cell\\.$/u.test(diagnostic.message)) {\n return {\n ...diagnostic,\n message: diagnostic.message.replace(\n / in [\\w.]+'s column cell\\.$/u,\n ` in ${channelsFile}'s column cell` +\n `${toStdout ? ' in any conversion that writes one' : ''}.`,\n ),\n };\n }\n if (\n diagnostic.code === 'DUPLICATE_LABEL' &&\n diagnostic.hint?.startsWith('Their names are suffixed')\n ) {\n return {\n ...diagnostic,\n hint:\n 'Their names are suffixed with the signal number so they stay distinguishable. ' +\n (writesSignals\n ? toStdout\n ? `--channels left this channel out, and --stdout writes no ${channelsFile} for ` +\n `its suffixed name to appear in — convert to a directory for that.`\n : `--channels left this channel out, so its suffixed name appears in ` +\n `${channelsFile}'s column cell and nowhere else.`\n : toStdout\n ? // The one of the three this pass was extended without at 0.9.29. `--stdout`\n // writes no channels.csv either, and the report saying this goes on to say\n // so two warnings later — \"--stdout writes no channels.csv to look this\n // channel up in\" — so one run carried both sentences about one file.\n `--annotations-only writes no signal table, and --stdout writes no ` +\n `${channelsFile} for the suffixed names to appear in — convert to a ` +\n `directory for that.`\n : '--annotations-only writes no signal table, so the suffixed names appear ' +\n `only in ${channelsFile}'s column cells.`),\n };\n }\n /*\n And the channel with no label at all, whose sentence ends in a column too.\n\n `EMPTY_LABEL` says where the name this tool invents for it lands, and both of its forms\n land it in a signal table: \"It will appear as `signal_1`\", and, where some other channel\n really carries that label, \"so both columns are suffixed with their position instead\".\n A run writing no signal table puts the name in one place, which is the cell the two\n rewrites above already name.\n */\n if (diagnostic.code === 'EMPTY_LABEL') {\n // Hedged under `--stdout`, where the cell is in a file that run does not write — the\n // wording 0.8.52 gave the same clause in NONPRINTABLE_LABEL, for the same reason.\n // Spelled out as its own string rather than by appending an s to the singular, which\n // reads as a number of seconds to the check that keeps those going through\n // `plainSeconds` — and does so whether it is in code or in a comment about it.\n const hedge = toStdout ? ' in any conversion that writes one' : '';\n const cell = `${channelsFile}'s column cell${hedge}`;\n const cells = `${channelsFile}'s column cells${hedge}`;\n return {\n ...diagnostic,\n message: diagnostic.message\n .replace(/ It will appear as (\"[^\"]*\")\\.$/u, ` It is named $1 in ${cell}.`)\n .replace(\n 'so both columns are suffixed with their position instead.',\n `so both are suffixed with their position in ${cells} instead.`,\n ),\n };\n }\n /*\n And the fourth calibration warning, which the three above were rewritten without.\n\n `UNUSABLE_PHYSICAL_RANGE` ends in the same sentence they do — \"Its cells are left empty\n rather than filled with a value the header cannot justify\" — and needs a header no\n fixture has, a span that underflows to zero or one too large to represent, which is how\n it stayed out of the sweep that found the others.\n */\n if (diagnostic.code === 'UNUSABLE_PHYSICAL_RANGE') {\n return {\n ...diagnostic,\n hint:\n `No samples are converted ${because}, so there are no cells to leave empty. ` +\n `${records('the physical range the header gives')}`,\n };\n }\n if (diagnostic.code === 'DEGENERATE_DIGITAL_RANGE') {\n return {\n ...diagnostic,\n hint:\n `No samples are converted ${because}, so there are no cells to leave empty. ` +\n `${records('the digital range the header gives')}`,\n };\n }\n if (diagnostic.code === 'DEGENERATE_PHYSICAL_RANGE') {\n return {\n ...diagnostic,\n message: diagnostic.message.replace(\n 'so every sample converts to the same value.',\n 'so every sample would convert to the same value.',\n ),\n hint:\n `No samples are converted ${because}. ${records('the calibration, one point wide')}`,\n };\n }\n if (diagnostic.code === 'INVERTED_PHYSICAL_RANGE') {\n return {\n ...diagnostic,\n hint:\n `No samples are converted ${because}. ` +\n `${records('the physical minimum and maximum in the order the header gives them, inversion included')}`,\n };\n }\n /*\n And the record this one could not place, which is timed from its neighbours in a signal\n table and nowhere else. Its events are exported whatever its position is: an onset is\n read off the event, not off the record it sits in, and `record_index` still names that\n record.\n */\n if (\n diagnostic.hint?.startsWith('That record is timed as if') === true ||\n diagnostic.hint?.startsWith('Those records are timed as if') === true\n ) {\n const one = diagnostic.hint.startsWith('That record');\n return {\n ...diagnostic,\n hint:\n `${writes}, so nothing is timed from ${one ? 'that record' : 'those records'}. ` +\n `The events in ${one ? 'it' : 'them'} carry their own onsets, and ` +\n `${annotationsFile}'s record_index still names ${one ? 'it' : 'them'}.`,\n };\n }\n if (diagnostic.code !== 'DISCONTINUOUS' || diagnostic.hint === undefined) return diagnostic;\n if (diagnostic.hint.startsWith('Each row carries its true recording time')) {\n return {\n ...diagnostic,\n hint:\n `${writes}, so nothing here is timed from the ` +\n `records. ${annotationsFile} carries each event's own onset, and the record it ` +\n 'came from in record_index.',\n };\n }\n if (diagnostic.hint.startsWith('Rows are written in file order')) {\n return {\n ...diagnostic,\n hint:\n `${writes}, so no time column is affected. ` +\n `${annotationsFile}'s record_index still names the record each event came from.`,\n };\n }\n if (diagnostic.hint.startsWith('Sample times are written from zero')) {\n return {\n ...diagnostic,\n hint: `${writes}, so no sample times are written at all.`,\n };\n }\n /*\n And the three that say the times are written as if the records were contiguous, which\n this pass had not been shown.\n\n Those are the answers for a file whose record positions are not recorded, or are\n contradicted by its own `EDF+C` marker — and they describe a time column. An\n `--annotations-only` run writes none, so all three promise something about rows it does\n not write:\n\n warning: This file is marked continuous (EDF+C), but 1 of its 3 data records says\n it starts somewhere other than where continuity puts it.\n Times are written as if the records were contiguous, which is what EDF+C\n means. ...\n warning: This file is marked discontinuous but has no annotation channel, so where\n its records sit in time is not recorded anywhere.\n Times are written as if the records were contiguous. Any gaps are lost.\n\n over an annotations.csv holding its header and no rows. The three sentences above this\n one were amended for exactly this at 0.8.x; these were the DISCONTINUOUS hints that do\n not begin with any of their phrases.\n\n What the header says about itself is still worth saying, so the messages stay. Only the\n clause about what a conversion makes of it was false, and what is true instead is that\n the events carry their own onsets whatever the records do.\n */\n if (diagnostic.hint.startsWith('Times are written as if the records were contiguous')) {\n return {\n ...diagnostic,\n hint:\n `${writes}, so no times are written from the ` +\n `records at all. ${annotationsFile} carries each event's own onset, which the ` +\n 'records do not decide.',\n };\n }\n // The marker warning's hint, which `withTimingPromiseKept` has already rewritten once and\n // which points at the warning under it. That pointer is still right and is what separates\n // the two, so it is the clause about the time column that goes and not the sentence.\n if (diagnostic.hint.startsWith('Where its records sit in time is not recorded in this file')) {\n return {\n ...diagnostic,\n hint:\n 'Where its records sit in time is not recorded in this file, and ' +\n `${writes} to time from them anyway — see the ` +\n 'warning below.',\n };\n }\n return diagnostic;\n });\n}\n\n/**\n * The sidecar files a `--stdout` run does not write, taken out of the sentences about them.\n *\n * `--stdout` puts one table on the stream and writes nothing else — \"No sidecar files are\n * written\", as `ConvertOptions` puts it. Two diagnostics raised before the destination is\n * known end by pointing at one of those files:\n *\n * warning: The header's start date and time (\"XX.XX.XX\" and \"YY.YY.YY\") are not a date\n * and a time, so the recording has no start instant.\n * ... and metadata.json records start_datetime_local as null.\n *\n * warning: This recording's timekeeping annotations place it 1e17s from its own start\n * date ...\n * ... Add the onsets in annotations.csv to recover absolute times.\n *\n * Neither file exists after such a run. The second is advice a reader can follow into an\n * empty directory — there is no directory.\n *\n * Amended where the answer is, the same way `withTimingPromiseKept` rewrites a `DISCONTINUOUS`\n * hint the parser could not have known was false, and `withoutFileRateWarning` drops a header\n * diagnostic the plan supersedes. A conversion to a directory keeps every word.\n */\nexport function withSidecarsNamed(\n diagnostics: readonly Diagnostic[],\n { toStdout, gzip }: { toStdout: boolean; gzip: boolean },\n): Diagnostic[] {\n if (!toStdout && !gzip) return [...diagnostics];\n const channels = outputCsvName('channels', gzip);\n const annotations = outputCsvName('annotations', gzip);\n return diagnostics.map((diagnostic) => {\n /*\n The last message of this kind, and the one that names its files mid-sentence.\n\n `NONPRINTABLE_LABEL` says where an invisible byte lands — the channel's name in\n signals.csv, a cell of channels.csv — and `--gzip` writes neither of those names. It was\n left out of 0.8.48 because the file is named inside a sentence assembled from which of\n the four header fields carry bytes, and out of 0.8.54 for the same reason. Renaming is\n all it needs, once the sentence is settled: this runs after `withSignalTableUnwritten`\n has had its say about the layout, so whichever file the sentence ended up naming is the\n one that gets the suffix.\n */\n /*\n And the same sentence under `--stdout`, where the signal table has no name at all.\n\n The `channels.csv` half of it has been hedged since 0.8.52 — \"in the channels.csv of any\n conversion that writes one\", which is true of a run that writes none. The half naming\n `signals.csv` was not, and `--stdout` is the mode this warning matters most in: it is\n the one that really does print the CSV to a terminal, which is what the hint two lines\n under it warns about.\n\n $ edf2csv control-labels.edf --stdout | less\n warning: Signal 1's label contains 1 control character (\\x07), which will appear as\n the channel's name in signals.csv, exactly as the header has it.\n\n There is no signals.csv. The byte is in the header row going past on the stream, which\n is where the reader is looking.\n */\n if ((gzip || toStdout) && diagnostic.code === 'NONPRINTABLE_LABEL') {\n return {\n ...diagnostic,\n message: diagnostic.message\n // Past a name the pass above already suffixed: `channels.csv.gz` contains\n // `channels.csv`, and a second rename made it `channels.csv.gz.gz`.\n .replace(\n /\\bsignals\\.csv\\b(?!\\.gz)/gu,\n toStdout ? 'the CSV on stdout' : outputCsvName('signals', true),\n )\n .replace(/\\bchannels\\.csv\\b(?!\\.gz)/gu, channels),\n };\n }\n /*\n The header's own `NO_SAMPLES`, which names the file that describes the channel it is\n about — and under `--stdout` there is no such file, so the reassurance is empty:\n\n $ edf2csv one-empty-channel.edf --stdout > rows.csv\n warning: Signal 1 (\"unused\") carries no samples at all (0 per data record).\n It is described in channels.csv but left out of the converted data.\n\n Under `--gzip` the file is there under another name. Both are settled here.\n */\n if (diagnostic.code === 'NO_SAMPLES' && diagnostic.hint?.startsWith('It is described in')) {\n return {\n ...diagnostic,\n hint: toStdout\n ? 'It is left out of the converted data, and --stdout writes no channels.csv to ' +\n 'describe it in — convert to a directory for that.'\n : `It is described in ${channels} but left out of the converted data.`,\n };\n }\n /*\n The collision hint, whose whole advice is a file to look the channel up in.\n\n A duplicate label, or a label that collides with another channel's `_ch` suffix, renames\n the column — and the sentence saying so ends by sending the reader to channels.csv for\n the channel's `signal_index`, since the renamed name is the only one in the table:\n\n $ edf2csv montage.edf --stdout > rows.csv\n warning: Signal 2 is labelled \"T8_ch0\", which is also the column name another\n channel's \"_ch\" suffix produces, so its column is \"T8_ch0_ch2\".\n Column names are unique; look this channel up in channels.csv by its\n signal_index.\n\n There is no channels.csv, and the renamed column is sitting in the header row on stdout\n with nothing to map it back. Under `--gzip` it was worse: `channels.csv.gz`, a\n compressed file no `--stdout` run writes either.\n\n Answered the way the two hints above answer it — the file is named, so that the reader\n knows what they are missing, and the command that produces it is named too.\n */\n if (toStdout && diagnostic.code === 'DUPLICATE_LABEL' && diagnostic.hint?.includes('look this channel up in')) {\n // \"Channel names\" under --layout long, where the name lands in the channel column;\n // \"Column names\" in the wide layout. Both are true of the stream, so the half of the\n // sentence that is about the rename is kept as the plan wrote it.\n const unique = diagnostic.hint.startsWith('Channel names') ? 'Channel names' : 'Column names';\n return {\n ...diagnostic,\n hint:\n `${unique} are unique, and --stdout writes no channels.csv to look this channel ` +\n `up in by its signal_index — convert to a directory for that.`,\n };\n }\n if (\n toStdout &&\n diagnostic.code === 'START_TIME_UNREADABLE' &&\n diagnostic.hint?.includes('metadata.json records')\n ) {\n return {\n ...diagnostic,\n hint:\n 'time_s is unaffected — it counts from the start of the recording either way. What ' +\n 'cannot be done is turning it into a wall-clock instant, and --stdout writes no ' +\n 'metadata.json to record start_datetime_local as null in.',\n };\n }\n if (\n diagnostic.code === 'DISCONTINUOUS' &&\n diagnostic.hint?.includes('onsets in annotations.csv')\n ) {\n return {\n ...diagnostic,\n hint: toStdout\n ? 'Sample times are written from zero instead, so every row is present and the ' +\n 'column increases. The onsets that recover absolute times are in the annotation ' +\n 'channel; --stdout writes no annotations.csv, so convert to a directory for them.'\n : 'Sample times are written from zero instead, so every row is present and the ' +\n `column increases. Add the onsets in ${annotations} to recover absolute times if ` +\n 'you need them.',\n };\n }\n return diagnostic;\n });\n}\n\n/**\n * `--annotations-only` on a recording that has no annotations.\n *\n * Exported and present-tense for the same reason `noSignalFile` above is. `--info` prints an\n * accurate line about it in the report body — \"and no annotations.csv either, since this\n * recording has no annotation channel\" — and raised nothing, so the one mode whose purpose is\n * to say what a conversion will do carried a shorter warning list than the conversion did:\n * `--info --json --annotations-only` on a plain EDF file listed no warning where converting\n * lists one, and `--info --strict`, which cli-reference.md recommends for screening a folder\n * before converting it, exited 0 where the conversion exits 1. Same defect as the one 0.7.84\n * closed for `NO_SAMPLES`, one flag over; both halves of the answer are in the file and the\n * options, which `--info` already has.\n */\nexport function noAnnotations(file: EdfFile, options: ConvertOptions): Diagnostic | null {\n if (options.annotationsOnly !== true || file.annotationSignals.length > 0) return null;\n return {\n code: 'NO_ANNOTATIONS',\n severity: 'warning',\n message:\n '--annotations-only was requested but this recording has no annotation channel, ' +\n 'so there are no events to export.',\n /*\n The format the file is in, rather than the one most files are in.\n\n \"Plain EDF files carry no annotations\" was said to every recording that reaches here,\n and two kinds of file reach it that are not plain EDF. A BioSemi `.bdf` was told about a\n format it is not in — this tool tells EDF and BDF apart everywhere else, down to the\n `BDF Annotations` label the specification gives the channel.\n\n And a file whose header says `EDF+C` while carrying no annotation channel at all is not\n a file for which having no events is ordinary: EDF+ keeps its events in that channel and\n is required to have one. The sentence read as reassurance about a file that is malformed.\n */\n hint: file.header.isEdfPlus\n ? `The header marks this ${describeFormat(file.header)}, and that format keeps its ` +\n `events in an annotation channel this file does not have. Convert without ` +\n `--annotations-only to get the signals.`\n : `Plain ${file.header.isBdf ? 'BDF' : 'EDF'} files carry no annotations. Convert ` +\n `without --annotations-only to get the signals.`,\n };\n}\n\n/**\n * `--annotations-only` that wrote no events, and why.\n *\n * The two causes are told apart because the answers are different. A channel holding nothing\n * but timekeeping entries has nothing to export and never will; a window that excluded every\n * event is a thing the caller can change, and the commonest reason is reading the window off\n * a clock the recording does not use — `--start` and `--end` are on the recording's own, which\n * starts at zero unless `--info` shows a \"Timed from\" line.\n *\n * `NO_ANNOTATIONS` rather than a new code, since it is the same statement its other raising\n * makes — there are no events to export — about the same flag, and a code is matched on by\n * scripts that should not have to learn a second one for the same fact.\n */\nexport function emptyAnnotations(\n total: number,\n window: { from: number; to: number },\n gzip = false,\n): Diagnostic {\n const windowed = (window.from !== -Infinity || window.to !== Infinity) && total > 0;\n return {\n code: 'NO_ANNOTATIONS',\n severity: 'warning',\n message: windowed\n ? `None of this recording's ${counted(total, 'event')} fall inside the requested ` +\n `window, so ${outputCsvName('annotations', gzip)} holds its header and no rows.`\n : `This recording's annotation channel carries no events, so ` +\n `${outputCsvName('annotations', gzip)} holds its header and no rows.`,\n hint: windowed\n ? /*\n Which is a line --info prints only when there is something to say.\n\n `Timed from` appears when the first sample is somewhere other than 0s — that is what\n the line is for — so on a recording timed from zero, which is most of them, this sent\n the reader to a line that is not in the report. The one hint whose whole job is \"you\n may be using the wrong clock\", pointing at nothing, on exactly the files where the\n window and the clock are hardest to tell apart.\n */\n '--start and --end are read on the recording\\'s own clock, which starts at 0s unless ' +\n '--info shows a \"Timed from\" line, and an event is kept when its onset falls inside ' +\n 'the window.'\n : 'The channel holds only the timekeeping entries that say where each data record ' +\n 'sits, and those are never exported.',\n };\n}\n\n/** Raised when the input moved while it was being read. See where it is pushed. */\nfunction inputChanged(hadChecksum: boolean): Diagnostic {\n return {\n code: 'INPUT_CHANGED',\n severity: 'warning',\n message:\n 'The input changed while it was being converted, so this output covers the file as ' +\n 'it was when the conversion started, not as it is now.',\n hint: hadChecksum\n ? 'No checksum was recorded: the bytes that were converted are no longer there to ' +\n 'hash. Convert again once the recording is finished.'\n : 'Convert again once the recording is finished to pick up the rest.',\n };\n}\n\nasync function writeMetadata(\n outputDir: string,\n inputPath: string,\n file: EdfFile,\n plan: ConversionPlan,\n written: readonly WrittenFile[],\n annotationCount: number,\n /** Hash of the bytes that were converted, or null when it could not be vouched for. */\n checksum: string | null,\n /** Whether the record start times could be read; see withTimingPromiseKept. */\n timedFromRecords: boolean,\n /** Whether each CSV starts with a byte order mark; see the `bom` field below. */\n bom: boolean,\n): Promise<void> {\n const { header } = file;\n\n /*\n The file as it was when it was opened, not as it is now.\n\n Both of these used to come from re-opening the path once the CSVs were written, which\n describes whatever answers to that name by then rather than what was converted. A\n recording still being written grew from 2,000 records to 3,000 mid-conversion and\n metadata.json recorded `data_records: 2000` — correct, the CSV holds 2,000 — beside the\n byte count and SHA-256 of the 3,000-record file. The two halves of one provenance record\n described two different files, and the checksum covered bytes nobody had converted.\n Replacing the file at that path did the same thing more thoroughly.\n\n `file.fileSize` is the number every record count and window in this output was derived\n from, and the hash is taken over exactly those bytes through the descriptor already open\n on them, so the record describes one file throughout.\n */\n const metadata = {\n tool: { name: 'edf2csv', version: TOOL_VERSION },\n source: {\n path: path.resolve(inputPath),\n bytes: file.fileSize,\n modified: new Date(file.modifiedAtOpenMs).toISOString(),\n sha256: checksum,\n },\n recording: {\n format: describeFormat(header),\n version: header.version,\n patient_id: header.patientId,\n recording_id: header.recordingId,\n // Zone-less on purpose: EDF records local wall-clock digits and no timezone.\n start_datetime_local: formatWallClock(header.startDateTime),\n start_date_raw: header.startDateRaw,\n start_time_raw: header.startTimeRaw,\n data_records: file.recordCount,\n data_records_declared: header.declaredRecordCount,\n record_duration_seconds: header.recordDuration,\n duration_seconds: file.durationSeconds,\n signal_count: header.signalCount,\n annotation_channels: file.annotationSignals.length,\n },\n conversion: {\n converted_at: new Date().toISOString(),\n start_seconds: plan.range.startSeconds,\n end_seconds: plan.range.endSeconds,\n whole_recording: plan.range.isWholeRecording,\n records_converted: [plan.range.startRecord, plan.range.endRecord],\n annotations_written: annotationCount,\n /*\n Which shape the signal table is in, which nothing recorded.\n\n A wide `signals.csv` and a long one are different files with different columns, and\n metadata.json described them identically — so a pipeline handed an output directory\n could not tell from the archive which it had. It matters most for `rate_groups` right\n below: in the wide layout those entries are one per file and their `channels` are that\n file's columns, and in the long layout every entry names the one shared table and its\n `channels` are values in that table's `channel` column. Same array, two readings, and\n no way to know which applied.\n */\n layout: plan.layout,\n /*\n The one option whose effect nothing else in this archive shows.\n\n `layout` is recorded on the stated grounds that \"the two have different columns and\n nothing else in the archive distinguishes them\". `--gzip` distinguishes itself: the\n names in `files` end `.csv.gz`. `--bom` puts three bytes in front of every CSV and\n leaves no other trace — and it is the option that decides whether reading the table\n back works. `csv.ts` sets out why: pandas strips the mark either engine, and Python's\n own `csv.reader` over a plain `open()` does not, nor does `readFileSync(path,\n 'utf8')`, so the first column name comes back as `\\ufefftime_s` and a lookup of\n `time_s` misses. A pipeline reading this document to find out how to open the files\n could not find out the one thing that changes the answer.\n */\n bom,\n files: written.map((f) => ({ name: f.name, rows: f.rows })),\n rate_groups: plan.groups.map((g) => ({\n file: g.fileName,\n sampling_rate_hz: g.rate,\n channels: g.channels.map((c) => c.column),\n decimals: g.channels.map((c) => c.decimals),\n })),\n },\n notes: withSidecarsNamed(\n withSignalTableUnwritten(\n [\n ...withTimingPromiseKept(withoutFileRateWarning(file.diagnostics), timedFromRecords),\n ...plan.diagnostics,\n ],\n plan.writeSignals,\n plan.gzip,\n convertedChannels(plan),\n ),\n // metadata.json is only written into a directory, so this is never the stdout case.\n { toStdout: false, gzip: plan.gzip },\n ).map((d) => ({\n code: d.code,\n severity: d.severity,\n message: d.message,\n })),\n };\n\n // Escaped like the two --json documents: metadata.json records the input's path, and a\n // `cat` of it should not be able to reorder the terminal. See escapeJsonText.\n const document = escapeJsonText(JSON.stringify(metadata, null, 2));\n await writeOutputFile(outputDir, 'metadata.json', `${document}\\n`);\n}\n\n\n"]}
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/convert/run.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,yFAAyF;AACzF,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAGrD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CA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C,QAAQ,CAAC;aAC5C,CAAC,CAAC;SACJ;QACD,KAAK,EAAE,iBAAiB,CACtB,wBAAwB,CACtB;YACE,GAAG,qBAAqB,CAAC,sBAAsB,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,gBAAgB,CAAC;YACpF,GAAG,IAAI,CAAC,WAAW;SACpB,EACD,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,IAAI,EACT,iBAAiB,CAAC,IAAI,CAAC,CACxB;QACD,oFAAoF;QACpF,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CACrC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACZ,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,OAAO,EAAE,CAAC,CAAC,OAAO;SACnB,CAAC,CAAC;KACJ,CAAC;IAEF,uFAAuF;IACvF,8EAA8E;IAC9E,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACnE,MAAM,eAAe,CAAC,SAAS,EAAE,eAAe,EAAE,GAAG,QAAQ,IAAI,CAAC,CAAC;AACrE,CAAC","sourcesContent":["/**\n * Executing a conversion.\n *\n * Everything is written in a single pass over the data records. All rate groups are\n * open at once and fed from the same batch of bytes, so a file is read once no\n * matter how many output tables it produces, and memory stays flat.\n */\n\nimport { createWriteStream, fstatSync } from 'node:fs';\nimport { lstat, mkdir, readdir, stat, writeFile } from 'node:fs/promises';\nimport { finished } from 'node:stream/promises';\nimport type { Writable } from 'node:stream';\nimport { createGzip, gzipSync } from 'node:zlib';\nimport path from 'node:path';\n\n// A destination is whatever the caller's shell handed over; see printable's own comment.\nimport { printable } from '../format/unprintable.js';\n\nimport type { RecordBatch } from '../edf/reader.js';\nimport { EdfFile } from '../edf/reader.js';\nimport { describeFormat, formatRate, formatRates, formatWallClock, startsFormula } from '../edf/header.js';\nimport type { Diagnostic } from '../edf/errors.js';\nimport { EdfError } from '../edf/errors.js';\nimport type { Annotation } from '../edf/annotations.js';\nimport {\n BufferedLineWriter,\n DEFAULT_FLUSH_THRESHOLD,\n UTF8_BOM,\n csvRow,\n escapeCsvField,\n} from '../format/csv.js';\nimport { counted, grouped, listed } from '../format/list.js';\nimport { escapeCharacter, escapeJsonText, unprintableIn } from '../format/unprintable.js';\nimport {\n makeSampleFormatter,\n makeTimeFormatter,\n newOffsetBudget,\n newSampleCacheBudget,\n plain,\n} from '../format/number.js';\nimport type { SampleFormatter } from '../format/number.js';\nimport { TIME_COLUMN } from './channels.js';\nimport { assertInputPath, assertOptions } from './options.js';\nimport { buildPlan, outputCsvName, withoutFileRateWarning } from './plan.js';\nimport type { ConversionPlan, PlanOptions, RateGroup } from './plan.js';\nimport { deriveRecordStarts, withTimingPromiseKept } from './timing.js';\nimport { sampleTimeIsInRange, toleranceFor } from './time-range.js';\nimport { VERSION as TOOL_VERSION } from '../version.js';\n\nexport { TOOL_VERSION };\n\nexport type ConversionErrorCode =\n | 'OUTPUT_EXISTS'\n | 'OUTPUT_UNWRITABLE'\n | 'INPUT_OUTPUT_COLLISION'\n | 'INPUT_UNREADABLE'\n | 'UNSUPPORTED_REQUEST'\n | 'CALLBACK_FAILED'\n | 'WRITE_FAILED';\n\n/**\n * Codes that mean the command cannot be carried out as written, rather than that something\n * about the file or the destination went wrong.\n *\n * The distinction is the one the exit codes draw: 1 is \"the file or the destination is the\n * problem\", 2 is \"the command line is the problem\". A caller with a `--stdout` conflict is\n * being told to change the flags — the hints say exactly that — so filing it under 1 sent\n * scripts looking at the disk. Exit 2 already covers checks that need the header first,\n * such as a `--channels` term matching nothing.\n */\nexport const USAGE_ERROR_CODES: ReadonlySet<ConversionErrorCode> = new Set(['UNSUPPORTED_REQUEST']);\n\nexport class ConversionError extends Error {\n readonly code: ConversionErrorCode;\n readonly hint: string | undefined;\n constructor(code: ConversionErrorCode, message: string, hint?: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'ConversionError';\n this.code = code;\n this.hint = hint;\n }\n}\n\nexport interface ConvertOptions extends PlanOptions {\n /**\n * Destination directory. Defaults to `defaultOutputDir(inputPath)`: the input's name with\n * its extension replaced by `_csv`, beside the input — `sleep-study.edf` gives\n * `sleep-study_csv`, not `sleep-study`.\n */\n outputDir?: string | undefined;\n /** Overwrite an existing output directory. */\n force?: boolean | undefined;\n /** Record a SHA-256 of the input in metadata.json. Costs one extra read of the file. */\n checksum?: boolean | undefined;\n /**\n * Write the signal CSV to stdout instead of to a directory.\n *\n * Only valid when the conversion produces exactly one signal file. In the default wide\n * layout a mixed-rate recording becomes several tables, and merging them into one stream\n * would mean inventing the samples this tool exists not to invent; `layout: 'long'` gives\n * one table for any recording, so it lifts the restriction. No sidecar files are written.\n */\n toStdout?: boolean | undefined;\n onProgress?: ((progress: ConversionProgress) => void) | undefined;\n}\n\nexport interface ConversionProgress {\n recordsDone: number;\n recordsTotal: number;\n bytesWritten: number;\n}\n\nexport interface WrittenFile {\n name: string;\n rows: number;\n}\n\nexport interface ConvertResult {\n outputDir: string;\n files: WrittenFile[];\n /**\n * True when a `--stdout` reader closed the pipe before the conversion finished.\n *\n * `edf2csv rec.edf --stdout | head -1` is an ordinary thing to type and not a failure, but\n * it is also not a conversion: the row count is rows formatted before the close was\n * noticed, which is neither the recording's total nor what the reader received.\n */\n readerHungUp: boolean;\n annotationCount: number;\n diagnostics: Diagnostic[];\n plan: ConversionPlan;\n file: EdfFile;\n elapsedMs: number;\n}\n\ninterface OpenGroup {\n group: RateGroup;\n writer: BufferedLineWriter;\n formatters: SampleFormatter[];\n formatTime: (recordStart: number, sample: number) => string;\n rows: number;\n /** Resolves once a compressed stream's bytes have reached the file behind it. */\n settled: Promise<void>;\n /** Detaches the compressor's error forwarding from a stream this tool does not own. */\n release: () => void;\n}\n\nexport async function convert(inputPath: string, options: ConvertOptions = {}): Promise<ConvertResult> {\n assertInputPath(inputPath);\n // And the bag behind it, here rather than at `buildPlan` below: `options.checksum` is read\n // before the plan is built, so a bag that is not one reached that line first. See\n // assertOptions for what a string in this position did.\n assertOptions(options);\n const startedAt = Date.now();\n const file = await EdfFile.open(inputPath);\n\n try {\n /*\n Hashed before a record is read, and only published if the file held still.\n\n A checksum taken afterwards cannot be trusted whichever descriptor it goes through. A\n file overwritten in place keeps its inode, so the open handle sees the new bytes too,\n and the old ones are simply gone — there is nowhere left to read what was converted.\n Taking it first at least means the hash describes the file the header was read from.\n\n What makes it a guarantee rather than a hope is the check at the end: if size or\n modification time moved at any point, the hash is dropped and the run says why. So\n `sha256` present means the file demonstrably did not change while it was read, and a\n recording still being written gets a null and a warning instead of a plausible hash of\n the wrong bytes. (A change reverted within the same modification timestamp would slip\n through; nothing short of copying the input first can close that.)\n */\n const checksumAtOpen = options.checksum === true ? await file.sha256() : null;\n\n // One pass over the annotation channel supplies everything annotation-related:\n // where each record sits in time, and the full event list. It reads the whole\n // file even when a window was requested, because an annotation inside the window\n // may be stored in a record outside it.\n const annotationData =\n file.annotationSignals.length > 0\n ? await file.readAnnotations()\n : { annotations: [] as Annotation[], recordStarts: [] as (number | null)[], malformed: 0 };\n\n const timing = deriveRecordStarts(file, annotationData);\n\n const plan = buildPlan(\n {\n signals: file.header.signals,\n recordDuration: file.header.recordDuration,\n recordCount: file.recordCount,\n hasAnnotationChannel: file.annotationSignals.length > 0,\n recordStarts: timing.starts,\n },\n options,\n );\n plan.diagnostics.push(...timing.diagnostics);\n\n if (options.toStdout === true) {\n const refusal = stdoutRefusal(file, plan);\n if (refusal) throw refusal;\n let readerHungUp = false;\n const written = await writeSignalFiles(file, plan, null, timing.starts, options, (hungUp) => {\n readerHungUp = hungUp;\n });\n if (await file.changedSinceOpen()) plan.diagnostics.push(inputChanged(false));\n return {\n outputDir: '-',\n files: written,\n readerHungUp,\n annotationCount: 0,\n // Over both lists, because the timing warnings are pushed onto the plan's.\n diagnostics: withSidecarsNamed(\n withSignalTableUnwritten(\n [\n ...withTimingPromiseKept(withoutFileRateWarning(file.diagnostics), timing.starts !== null),\n ...plan.diagnostics,\n ],\n plan.writeSignals,\n plan.gzip,\n convertedChannels(plan),\n true,\n ),\n { toStdout: true, gzip: plan.gzip },\n ),\n plan,\n file,\n elapsedMs: Date.now() - startedAt,\n };\n }\n\n /*\n A destination whose last component is `.` or `..` does not name a directory of its own.\n\n `prepareOutputDir` claims the final component with a single non-recursive mkdir, having\n created its parents recursively — which is what makes two conversions racing for one\n directory safe. `path.dirname(\"out/.\")` is `\"out\"`, so for these the parent step creates\n the destination itself and the claim then asks the filesystem to make `.` inside it,\n which always exists. The result was a refusal naming a directory this same run had just\n made, one line after making it:\n\n edf2csv rec.edf --out ./fresh/.\n error: \"./fresh/.\" already exists.\n Pass --force to overwrite it, or --out to choose a different directory.\n\n Exit 1, nothing converted, and an empty `fresh/` left on disk. `--force` does not help:\n the claim fails the same way whatever it is told, so the path was unusable rather than\n occupied.\n\n Normalised only in that case, so `--out ./converted` keeps the spelling it was given —\n that one is already how the directory is found on disk, which is what `output_dir`\n promises, and rewriting it to `converted` would churn every example for no gain.\n */\n const asked = options.outputDir ?? defaultOutputDir(inputPath);\n const outputDir = /(?:^|[\\\\/])\\.\\.?$/u.test(asked) ? path.normalize(asked) : asked;\n await assertInputDoesNotOverlapOutputs(inputPath, outputDir, file, plan, options);\n await prepareOutputDir(outputDir, options.force === true);\n\n const written: WrittenFile[] = [];\n\n if (plan.writeSignals && plan.groups.length > 0) {\n const signals = await writeSignalFiles(file, plan, outputDir, timing.starts, options);\n written.push(...signals);\n } else {\n const missing = noSignalFile(file, plan);\n if (missing) plan.diagnostics.push(missing);\n }\n\n const noEvents = noAnnotations(file, options);\n if (noEvents) plan.diagnostics.push(noEvents);\n\n let annotationsWritten = 0;\n if (file.annotationSignals.length > 0) {\n const window = requestedAnnotationWindow(options, plan.range.recordingStartSeconds);\n // Reported against the rows that will be written, not against the file; see\n // durationDiagnostics.\n plan.diagnostics.push(\n ...durationDiagnostics(annotationData.annotations, window, plan.gzip),\n );\n plan.diagnostics.push(\n ...descriptionDiagnostics(annotationData.annotations, window, plan.gzip),\n );\n const result = await writeAnnotationsCsv(\n outputDir,\n annotationData.annotations,\n window,\n options.gzip === true,\n options.bom === true,\n );\n written.push(result);\n annotationsWritten = result.rows;\n /*\n A run whose only table came out empty, which nothing said.\n\n `emptyWindow`'s own docstring states the rule this was breaking: \"everywhere else that\n a request produces nothing this tool says so: a --channels term matching nothing is an\n error, and --annotations-only on a file with no events raises NO_ANNOTATIONS.\" The\n second half is true only of a file with no annotation *channel*. Give the flag a\n recording whose channel carries nothing but timekeeping, or a window its events fall\n outside, and the run writes an annotations.csv holding one header line, prints \"Wrote\n … annotations.csv 0 rows\", exits 0 and passes --strict — which is exactly the shape\n EMPTY_WINDOW exists to refuse on the signal side, arriving by the other route.\n\n Only when there is no signal table either, so this is the whole of what the run\n produced. A windowed conversion of a recording whose events sit elsewhere is\n ordinary and its signals are the point; warning there would fire on most windows of\n most annotated recordings, which is how a warning stops being read.\n */\n if (!plan.writeSignals && annotationsWritten === 0) {\n plan.diagnostics.push(emptyAnnotations(annotationData.annotations.length, window, plan.gzip));\n }\n }\n\n written.push(\n await writeChannelsCsv(outputDir, file, plan, options.gzip === true, options.bom === true),\n );\n\n /*\n The file moved under the conversion. Said out loud, because nothing else shows it.\n\n The CSVs are still correct for the records that were read, and metadata.json still\n describes the file as it was opened — so the record is consistent with the output\n whatever happens here. What stops being true is that the checksum describes the bytes\n that were converted, since an in-place overwrite leaves nowhere to read them from. It\n is dropped rather than guessed at.\n */\n const changed = await file.changedSinceOpen();\n if (changed) plan.diagnostics.push(inputChanged(options.checksum === true));\n\n await writeMetadata(\n outputDir,\n inputPath,\n file,\n plan,\n written,\n annotationsWritten,\n changed ? null : checksumAtOpen,\n timing.starts !== null,\n options.bom === true,\n );\n\n const stale = await findStaleOutput(outputDir, written);\n\n return {\n outputDir,\n files: written,\n readerHungUp: false,\n annotationCount: annotationsWritten,\n // The directory path needs it too: `--gzip` changes the names, and two of these\n // sentences are a file name and nothing else. See withSidecarsNamed.\n diagnostics: withSidecarsNamed(\n withSignalTableUnwritten(\n [\n ...withTimingPromiseKept(withoutFileRateWarning(file.diagnostics), timing.starts !== null),\n ...plan.diagnostics,\n ...stale,\n ],\n plan.writeSignals,\n plan.gzip,\n convertedChannels(plan),\n ),\n { toStdout: false, gzip: plan.gzip },\n ),\n plan,\n file,\n elapsedMs: Date.now() - startedAt,\n };\n } finally {\n await file.close();\n }\n}\n\n/*\n Files this tool produces, used to spot leftovers from an earlier conversion.\n\n The rate part has to allow every shape a filename can now take, not just the plain ones:\n\n signals_256hz.csv an integer rate\n signals_12_5hz.csv a fractional rate, decimal point written as an underscore\n signals_1_000e-7hz.csv a rate small enough to need exponent form (0.2.2)\n signals_256hz.csv.gz any of the above, compressed (0.3.0)\n signals_0hz_2.csv a second group whose rate slug collided (0.2.1)\n\n The previous `[\\w.]+hz` matched neither of the last two — `-` and `+` are not word\n characters, and the collision suffix falls after the `hz`. Both were introduced by\n recent changes and both silently stopped being recognised as this tool's own output, so\n leftovers of exactly those kinds went unreported: the one situation the warning exists\n for. Requiring a digit after the underscore keeps a user's own `signals_notes.csv` out.\n\n And `signals_Infinityhz.csv`, which is a name this tool writes and the digit rule then\n excluded. A record duration too small to divide into overflows the rate — `rateSlug` says\n `Infinityhz` and the writer opens that file, with the TIME_RESOLUTION warning beside it\n saying no rows will go in it — so a mixed-rate run of such a file leaves two `signals_*`\n files behind and the next conversion into that directory named one of them:\n\n warning: signals_1e+308hz.csv is left over from an earlier conversion into this\n directory and was not rewritten.\n\n with `signals_Infinityhz.csv` sitting beside it, from the same run, unmentioned. Spelled\n out rather than loosened, so a user's own `signals_notes.csv` stays out for the reason\n above; the check below holds the pattern against every name `rateSlug` can produce.\n*/\nconst OUTPUT_PATTERN =\n /^(signals(_(\\d[\\w.+-]*|Infinity)hz(_\\d+)?)?\\.csv(\\.gz)?|annotations\\.csv(\\.gz)?|channels\\.csv(\\.gz)?|metadata\\.json)$/u;\n\n/**\n * Detect output from a previous run that this one did not replace.\n *\n * `--force` overwrites files but does not empty the directory, so converting a\n * mixed-rate recording and then a single-rate one into the same place leaves\n * `signals_256hz.csv` sitting next to a fresh `signals.csv`. Both look current.\n * Nothing is deleted here — the user is told, and decides.\n */\nasync function findStaleOutput(\n outputDir: string,\n written: readonly WrittenFile[],\n): Promise<Diagnostic[]> {\n const entries = await readdir(outputDir).catch(() => null);\n if (!entries) return [];\n\n // metadata.json is rewritten on every run but is not part of the reported file list.\n const fresh = new Set([...written.map((f) => f.name), 'metadata.json']);\n const stale = entries.filter((name) => OUTPUT_PATTERN.test(name) && !fresh.has(name)).sort();\n if (stale.length === 0) return [];\n\n return [\n {\n code: 'STALE_OUTPUT',\n severity: 'warning',\n /*\n Through `listed`, like every other message that enumerates something this run does not\n control. How many stale files a directory holds is up to the directory, and a\n mixed-rate recording converted into a reused one is exactly how it fills up: 120 old\n `signals_<rate>hz.csv` files produced a single 2,373-character warning line. That is\n the failure `listed` was written for — its own comment quotes the 1,600-character\n version of it — and this was the one message still joining its own list.\n\n The hint said \"Delete them\" whatever the count, so one stale file read \"signals_999hz\n .csv is left over ... Delete them.\"\n */\n message:\n `${listed(stale)} ${stale.length === 1 ? 'is' : 'are'} left over from an earlier ` +\n `conversion into this directory and ${stale.length === 1 ? 'was' : 'were'} not rewritten.`,\n hint:\n `Delete ${stale.length === 1 ? 'it' : 'them'}, or convert into a fresh directory, so ` +\n 'the two runs do not get mixed up.',\n },\n ];\n}\n\nexport function defaultOutputDir(inputPath: string): string {\n /*\n The third export whose only argument is a path, and the one left handing a wrong value on.\n\n `path.basename` refuses a non-string with Node's own text — `The \"path\" argument must be\n of type string. Received type number (5)` — which names a parameter of `path`, not one of\n this function, and reaches a caller who never called `path`. `convert` got this check in\n 0.7.x and `EdfFile.open` in 0.8.9; this is what the api page tells you to call to find out\n where those two would write, so it is reached by exactly the same caller.\n */\n assertInputPath(inputPath);\n const base = path.basename(inputPath, path.extname(inputPath));\n return path.join(path.dirname(inputPath), `${base}_csv`);\n}\n\n/** Never let an output target resolve to the recording being read, even with --force. */\nasync function assertInputDoesNotOverlapOutputs(\n inputPath: string,\n outputDir: string,\n file: EdfFile,\n plan: ConversionPlan,\n options: ConvertOptions,\n): Promise<void> {\n /*\n The names this run will actually write, compressed ones included.\n\n The rate files come from the plan and already carry `.csv.gz` under --gzip; the sidecars\n were spelled out here and did not. So a compressed run checked two names it would never\n write and missed the two it would: a recording sitting at <outdir>/channels.csv.gz was\n overwritten by its own conversion, with --force, reported as a success. The same file\n named signals.csv.gz was refused, which is what gives the oversight away.\n */\n const suffix = options.gzip === true ? '.csv.gz' : '.csv';\n const names = new Set(plan.groups.map((group) => group.fileName));\n if (file.annotationSignals.length > 0) names.add(`annotations${suffix}`);\n names.add(`channels${suffix}`);\n names.add('metadata.json');\n\n const inputResolved = path.resolve(inputPath);\n /*\n Tolerant of the input going away, like every other stat in this function.\n\n This one was bare, so a recording renamed or unlinked between `EdfFile.open` and here threw\n Node's own error straight out of `convert()`:\n\n Error: ENOENT: no such file or directory, stat './link.edf'\n\n with no `code` this tool defines and no hint — a sixth error type from a function the API\n page says throws five, on the one path where a file moving under a conversion is the\n documented ordinary case. The descriptor is already open, so the conversion itself is fine;\n what is lost is the inode comparison, and `samePath` below still answers the case that\n matters when the two names are the same name.\n */\n const inputInfo = await stat(inputPath).catch(() => null);\n\n for (const name of names) {\n const target = path.join(outputDir, name);\n const targetResolved = path.resolve(target);\n const targetInfo = await stat(target).catch(() => null);\n const samePath = targetResolved === inputResolved;\n const sameFile =\n targetInfo !== null &&\n inputInfo !== null &&\n targetInfo.dev === inputInfo.dev &&\n targetInfo.ino === inputInfo.ino;\n if (!samePath && !sameFile) continue;\n\n throw new ConversionError(\n 'INPUT_OUTPUT_COLLISION',\n `Output file \"${target}\" is the same file as the input recording.`,\n 'Choose a separate directory with --out. The input was not modified.',\n );\n }\n}\n\nasync function prepareOutputDir(dir: string, force: boolean): Promise<void> {\n /*\n The destination, quoted into every refusal below, and shown rather than pasted.\n\n `--out` is whatever the caller's shell handed over, and `printableLines` escapes every\n control byte in a message except the one that makes a line break — it splits on those\n first, to keep the author's own lines. So a newline in a destination cut the refusal's\n first line in half:\n\n error: \"out/ex\n ists\" already exists.\n\n which is the line this tool's comments keep insisting stays whole, because it is the one a\n log gets grepped for. Same in `EdfFile.open`'s path and in a `--channels` term; all three\n go through `printable` now, where the summary and the report have always put them.\n */\n const shownDir = printable(dir);\n /*\n Claim the directory with a single atomic mkdir rather than asking whether it exists\n and then creating it.\n\n Checking first left a window between the two: two conversions started together both\n saw \"not there\", both proceeded, and both opened write streams on the same signals.csv.\n Neither reported anything — both exited 0, having half-written one file between them.\n A non-recursive mkdir cannot do that. Exactly one caller creates the directory; every\n other one gets EEXIST from the filesystem and takes the already-exists path below.\n\n Parents are still created recursively, since --out ./a/b/c should work. Only the final\n component is the claim.\n */\n const parent = path.dirname(dir);\n if (parent && parent !== dir) {\n try {\n await mkdir(parent, { recursive: true });\n } catch (cause: unknown) {\n // A parent that is a regular file surfaces as EEXIST naming the parent, which reads\n // as though the destination already exists rather than as \"you cannot put a\n // directory inside a file\". Name the real obstacle instead of the errno.\n const info = await stat(parent).catch(() => null);\n if (info && !info.isDirectory()) {\n throw new ConversionError(\n 'OUTPUT_UNWRITABLE',\n `Cannot create \"${shownDir}\": \"${printable(parent)}\" is a file, not a directory.`,\n 'Choose a destination whose parent directories are directories, with --out.',\n );\n }\n throw new ConversionError(\n 'OUTPUT_UNWRITABLE',\n `Cannot create \"${shownDir}\": ${describeFsError(cause)}.`,\n createHint(cause),\n );\n }\n }\n\n let claimed = true;\n try {\n await mkdir(dir);\n } catch (cause: unknown) {\n if ((cause as NodeJS.ErrnoException).code !== 'EEXIST') {\n throw new ConversionError(\n 'OUTPUT_UNWRITABLE',\n `Cannot create \"${shownDir}\": ${describeFsError(cause)}.`,\n createHint(cause),\n );\n }\n claimed = false;\n }\n\n if (!claimed) {\n const existing = await stat(dir).catch(() => null);\n\n // --force means \"replace my previous output\", not \"write output files into\n // whatever this happens to be\". Pointing it at a regular file needs saying so.\n if (existing && !existing.isDirectory()) {\n throw new ConversionError(\n 'OUTPUT_UNWRITABLE',\n `\"${shownDir}\" is a file, but the converted data needs a directory.`,\n 'Choose a directory with --out.',\n );\n }\n /*\n A link to nothing, which `stat` cannot see and `mkdir` will not write through.\n\n `stat` follows symbolic links, so a dangling one leaves `existing` null and fell through\n to the sentence below — which is the one claim that is not true of it:\n\n $ edf2csv rec.edf --out link-to-nowhere\n error: \"link-to-nowhere\" already exists.\n Pass --force to overwrite it, or --out to choose a different directory.\n\n Nothing is there. And following that advice made it worse: `--force` reached the writer\n and came back as `Writing to \"link-to-nowhere\" failed: part of the path does not exist.\n The files written so far are incomplete and should not be used` — a conversion failure,\n about files that were never written, advising the reader to make sure nothing is\n removing a directory that never existed.\n\n A broken link in a batch's destination is how this arrives: the run before it wrote into\n a mount that has since gone.\n */\n if (!existing && (await lstat(dir).catch(() => null))) {\n throw new ConversionError(\n 'OUTPUT_UNWRITABLE',\n `\"${shownDir}\" is a symbolic link to something that does not exist, so nothing can be ` +\n `written there.`,\n 'Remove the link, or choose a directory with --out. --force writes into a directory ' +\n 'that is already there, and a link to nowhere is not one.',\n );\n }\n if (!force) {\n /*\n What `--force` does, rather than what it sounds like it does.\n\n \"Overwrite it\" reads as a claim about the directory, and the neighbouring hint said so\n outright — \"--force replaces a previous output directory\". It does neither. It writes\n into the directory: files of the same name are replaced and everything else is left\n exactly where it was, which is why `STALE_OUTPUT` exists to report what stayed. The\n flag list has described it accurately since it was written — \"write into the output\n directory if it already exists\" — so the one sentence a reader meets at the moment\n they decide whether to pass it was the one contradicting the other two.\n\n The difference is a directory that ends up holding two conversions. Convert a\n mixed-rate recording and then a single-rate one into the same place with `--force`,\n and `signals_256hz.csv` sits beside a fresh `signals.csv` under a channels.csv and a\n metadata.json describing only the second — which is exactly the outcome a reader who\n was told the directory would be replaced does not expect, and does not check for.\n */\n throw new ConversionError(\n 'OUTPUT_EXISTS',\n `\"${shownDir}\" already exists.`,\n 'Pass --force to write into it, leaving whatever else it holds, or --out to choose ' +\n 'a different directory.',\n );\n }\n }\n}\n\n/**\n * Turn a Node filesystem error into something a person can act on: an errno as a sentence,\n * so Node's own text never reaches the screen.\n *\n * Exported for the CLI's last-resort stdout listener, which is the third and last place a\n * write failure becomes a message and the one that was still printing `ENOSPC: no space left\n * on device, write`.\n */\nexport function describeFsError(cause: unknown): string {\n const code = (cause as NodeJS.ErrnoException | undefined)?.code;\n if (code === 'EACCES' || code === 'EPERM') return 'permission denied';\n if (code === 'ENOSPC') return 'the disk is full';\n // The one that actually happens on a shared filesystem, and the one this list left out.\n if (code === 'EDQUOT') return 'you are over your disk quota on this filesystem';\n if (code === 'ENOTDIR') return 'part of the path is a file, not a directory';\n if (code === 'EROFS') return 'the filesystem is read-only';\n if (code === 'ENAMETOOLONG') return 'the path is too long';\n /*\n The two `writeHint` knew and this did not, which showed once the write failures started\n coming through here: `writeHint` reads the same errno off the same error and has a\n sentence for eleven of them, this had seven, and the gap was the two that only a write\n reaches. `EISDIR` is a directory sitting where an output file belongs, which is the\n commonest way to make one of these happen on purpose.\n\n `EPIPE` is deliberately not here. The writer treats a reader hanging up as the ordinary\n end of a pipeline rather than as a failure, so it never becomes a message.\n */\n if (code === 'EISDIR') return 'a directory is sitting there already';\n if (code === 'EMFILE' || code === 'ENFILE') return 'too many files are open';\n /*\n The one this list could not describe, and the recursive mkdir above is what makes it\n surprising: every parent is created on the way, so \"no such file or directory\" is not a\n parent that was missing. It is a component that exists and leads nowhere — a symbolic\n link with no target is the way to get one — or a directory removed by something else\n between the two calls.\n\n Missing it meant the fallback ran, which is Node's own text, complete with the internal\n call that raised it:\n\n error: Cannot create \"dangle/x\": ENOENT: no such file or directory, mkdir 'dangle'.\n Check the path exists and that you have permission to write there.\n\n Keeping that off the screen is the whole purpose of the six lines above it.\n */\n if (code === 'ENOENT') return 'part of the path does not exist';\n return cause instanceof Error ? cause.message : String(cause);\n}\n\nasync function writeSignalFiles(\n file: EdfFile,\n plan: ConversionPlan,\n outputDir: string | null,\n recordStarts: Float64Array | null,\n options: ConvertOptions,\n onHangUp?: (hungUp: boolean) => void,\n): Promise<WrittenFile[]> {\n // One budget for every table in this conversion, not one per table: see OffsetBudget.\n const offsets = newOffsetBudget();\n // Likewise one for every channel, not one per channel: see SampleCacheBudget.\n const sampleCaches = newSampleCacheBudget();\n // Only the stdout path needs this; --out finds a full disk on its own, because it always\n // has another file to write afterwards. See auditStdout.\n const audit = outputDir === null ? auditStdout() : null;\n /*\n In the long layout every group writes into one table, so they share one stream. Opening\n a stream per group on the same path is what the rate-slug collision fix in groupByRate\n was about: two writers on one file interleave rows under a header naming one of them.\n */\n let shared: {\n stream: Writable;\n settled: Promise<void>;\n release: () => void;\n target: Writable;\n writer: BufferedLineWriter;\n } | null = null;\n\n /*\n One buffer's worth of memory for the conversion, not one per table.\n\n Every group had its own writer at the default 1 MiB threshold, so pending output was\n group count × 1 MiB before anything drained. A 6.5 MB recording with 40 sampling rates\n — the header allows thousands of channels, and a research montage really does mix a\n dozen rates — died with a raw V8 heap out-of-memory and exit 134 under a 96 MB cap,\n while the site advertises 48 MB. The recording is small; it is the fan-out that is not.\n\n Split evenly with a floor, so the single-rate case, which is nearly every recording,\n keeps exactly the buffer it always had, and forty tables cost one megabyte between them\n rather than forty. The floor is what the sum is bounded by rather than the split: past\n 128 groups every table takes the 8 KiB minimum, so the total grows again from there.\n The long layout shares one writer already and is unaffected either way.\n */\n const MIN_FLUSH_THRESHOLD = 8 * 1024;\n const flushThreshold = Math.max(\n MIN_FLUSH_THRESHOLD,\n Math.floor(DEFAULT_FLUSH_THRESHOLD / Math.max(1, plan.groups.length)),\n );\n /*\n The stream's own buffer is the other half of the same sum.\n\n 0.5.6 shared the line-buffer budget and left `createWriteStream` at its 64 KiB default,\n which is per stream: 200 rate groups meant 12.8 MB of stream buffer on top of 12.8 MB of\n line buffer, and an 855 KB recording still died at a 48 MB cap. Shared the same way, with\n a floor that keeps an ordinary conversion writing in useful-sized pieces.\n */\n const streamBuffer = Math.max(\n 16 * 1024,\n Math.floor(DEFAULT_FLUSH_THRESHOLD / Math.max(1, plan.groups.length)),\n );\n\n const open: OpenGroup[] = plan.groups.map((group, groupIndex) => {\n // A null directory means the single table goes to stdout. process.stdout is already a\n // writable stream, so the same buffered writer and backpressure handling apply.\n const target =\n shared?.target ??\n (outputDir === null\n ? process.stdout\n : createWriteStream(path.join(outputDir, group.fileName), {\n highWaterMark: streamBuffer,\n }));\n const { stream, settled, release } = shared ?? compressed(target, options.gzip === true);\n /*\n Under --gzip the writer feeds the compressor, so its byte count is the CSV before\n compression and says nothing about what reached the descriptor. The compressor's own\n output is what stdout is handed, so that is what is counted. `pipe` uses a 'data'\n listener of its own and a second one is delivered the same chunks.\n\n Once per stream, which in the long layout is once for all the groups. Attaching per\n group put N listeners on the one shared compressor, so every chunk was counted N\n times: `--stdout --layout long --gzip` on a 40-rate recording claimed 622,240 of\n 622,240 bytes where 15,556 had been written, failed with a disk-full error over a\n perfectly good file, and printed Node's MaxListenersExceededWarning to stderr on the\n way past ten. 0.5.4 fixed the same arithmetic in the uncompressed branch and left\n this one, because the uncompressed branch is where the count is a sum and this one is\n where it is a subscription.\n */\n if (audit && stream !== target && !shared) {\n stream.on('data', (chunk: Buffer) => audit.count(chunk.length));\n }\n /*\n One writer, not one per group, when the table is shared. Separate writers over one\n stream each hold their own buffer and flush on their own schedule, so the rows would\n reach the file in whatever order the buffers filled — which is not the order they\n were produced in, and the long layout's whole claim is that its rows are in time\n order.\n */\n const writer = shared?.writer ?? new BufferedLineWriter(stream, flushThreshold);\n if (plan.layout === 'long' && !shared) shared = { stream, settled, release, target, writer };\n\n // Only the first group writes the header of a shared table, and the mark before it.\n if (plan.layout !== 'long' || groupIndex === 0) {\n if (options.bom === true) writer.push(UTF8_BOM);\n writer.pushLine(\n plan.layout === 'long'\n ? csvRow([TIME_COLUMN, 'channel', 'value'])\n : csvRow([TIME_COLUMN, ...group.channels.map((c) => c.column)]),\n );\n }\n return {\n group,\n writer,\n formatters: group.channels.map((c) => makeSampleFormatter(c.signal, c.decimals, sampleCaches)),\n formatTime: makeTimeFormatter(\n group.samplesPerRecord,\n group.rate,\n group.timeDecimals,\n offsets,\n ),\n rows: 0,\n settled,\n release,\n };\n });\n\n try {\n const written = await streamSignalRows(file, plan, open, recordStarts, options);\n\n /*\n Checked once everything has been flushed and ended, and not when the reader hung up.\n\n `--stdout | head -1` closes the pipe on purpose, which is a shell idiom rather than a\n failure. A pipe is not a regular file, so auditStdout declines it anyway — the second\n guard is here because the cost of getting this one wrong is reporting a failure for a\n command that worked.\n */\n if (audit) {\n // Uncompressed, the writer hands its bytes straight to the descriptor; compressed,\n // they were counted on the compressor's way out.\n if (options.gzip !== true) {\n /*\n Once per writer, not once per group. The long layout gives every group the same\n writer, so counting per group multiplied its byte total by the number of rates:\n `--stdout --layout long` on a three-rate recording handed over 32,043 bytes, was\n credited with 96,129, and failed with a disk-full error for a file that was\n complete on disk. It only showed with stdout redirected to a regular file, since\n that is the one case the audit applies to — which is the command the --layout\n documentation gives.\n */\n for (const writer of new Set(open.map((entry) => entry.writer))) {\n audit.count(writer.bytesOut);\n }\n }\n if (!open.some((entry) => entry.writer.hungUp)) audit.verify();\n }\n onHangUp?.(open.some((entry) => entry.writer.hungUp));\n return written;\n } catch (cause) {\n for (const entry of open) entry.writer.destroy();\n\n /*\n Reading and writing both fail through here, and both were reported as writing.\n\n A recording that shrinks mid-conversion — still being written by the acquisition\n software, say — raises the reader's own error, which names the record and says the\n file changed size while it was being read. That precise diagnosis was then filed under\n `Writing to \"<dir>\" failed` and given the hint about freeing disk space, which sends\n someone to look at the one part of the system that was working.\n\n The reader's message and its advice are kept; only the note about partial output is\n added, since that much is true of either failure.\n */\n // A ConversionError arrived already saying what went wrong — a callback that threw, say.\n // Wrapping it again turned \"the onProgress callback threw\" into `Writing to \"out\"\n // failed: the onProgress callback threw`, under a hint about checking the destination.\n if (cause instanceof ConversionError) throw cause;\n\n if (cause instanceof EdfError) {\n const where = outputDir === null ? 'stdout' : `\"${outputDir}\"`;\n throw new ConversionError(\n 'INPUT_UNREADABLE',\n cause.message,\n `${cause.hint ? `${cause.hint} ` : ''}What was written to ${where} before it failed is ` +\n `incomplete and should not be used.`,\n );\n }\n\n /*\n Through `describeFsError`, like the destination errors above, and not through Node's\n own text.\n\n That function exists to keep an errno and the internal call that raised it off the\n screen — its comment says so in as many words, quoting the leak it was written for:\n `Cannot create \"dangle/x\": ENOENT: no such file or directory, mkdir 'dangle'.` The\n write failures never joined it, so a directory sitting where signals.csv belongs read\n\n error: Writing to \"out\" failed: EISDIR: illegal operation on a directory, open 'out/signals.csv'\n\n with the errno token, the syscall, the path repeated, and no full stop — the one\n diagnostic shape this tool went back and fixed. The hint printed directly under it has\n always read the same errno and said \"A directory is sitting where that file belongs\",\n so the answer was in hand; it was the sentence above it that had not asked.\n */\n throw new ConversionError(\n 'WRITE_FAILED',\n `Writing to ${outputDir === null ? 'stdout' : `\"${outputDir}\"`} failed: ` +\n `${describeFsError(cause)}.`,\n writeHint(cause, outputDir === null),\n );\n }\n}\n\n/**\n * Whether two sample times are close enough that only rounding could separate them.\n *\n * A relative epsilon, because the gap between doubles grows with magnitude. Well below any\n * real sample interval — the finest a recording can declare is bounded by its record\n * duration and samples-per-record fields — and well above the one-ULP disagreement that two\n * exact divisions of the same instant produce.\n */\nfunction nearlyEqual(a: number, b: number): boolean {\n return Math.abs(a - b) <= Math.max(Math.abs(a), Math.abs(b)) * 1e-12;\n}\n\n/**\n * One record's samples in the long layout: `time_s,channel,value`, in time order.\n *\n * The groups are merged rather than written one after another. Every sample in a record\n * falls inside that record's span, so taking the earliest next sample across the groups\n * each time leaves the whole file sorted by `time_s` — which is the only thing that makes a\n * mixed-rate long table useful, since sorting 3 million rows afterwards is the reader's\n * problem and a large one.\n *\n * Ties go to the group with the higher rate, which is the order the groups are already in.\n * Within a sample time the channels come out in the order the file declares them.\n */\nasync function writeLongRecord(\n file: EdfFile,\n open: readonly OpenGroup[],\n batch: RecordBatch,\n recordInBatch: number,\n recordStart: number,\n range: ConversionPlan['range'],\n): Promise<void> {\n const writer = open[0]?.writer;\n if (!writer) return;\n\n const cursors = new Int32Array(open.length);\n /* Reused across sample times so a three-million-row conversion allocates one of these. */\n const due: { entry: OpenGroup; groupIndex: number; sample: number; channel: number }[] = [];\n\n for (;;) {\n let earliest = Infinity;\n let source = -1;\n let sourceSample = 0;\n for (let g = 0; g < open.length; g++) {\n const entry = open[g];\n if (!entry) continue;\n const sample = cursors[g] ?? 0;\n if (sample >= entry.group.samplesPerRecord) continue;\n const time = recordStart + sample / entry.group.rate;\n if (time < earliest) {\n earliest = time;\n source = g;\n sourceSample = sample;\n }\n }\n if (earliest === Infinity) return;\n\n /*\n Everything at this instant, in the order the file declares its channels.\n\n Groups are ordered by rate, largest first, because that is how the wide layout names\n its files. Emitting a tie group by group therefore ordered the channels by descending\n sampling rate — so a recording declaring `slow, medium, fast` wrote `fast, medium,\n slow`, while the documentation promised file order and channels.csv listed file order.\n Signal index is the file's own order, and the only one a reader can predict.\n\n \"At this instant\" is decided on the time as written, not on the double. `s / rate` for\n two channels at one moment need not give the same double: a 0.3 s record holding 12 and\n 4 samples makes 40 Hz and 13.333… Hz, and 9/40 is 0.22500000000000000555 while 3/13.333…\n is 0.22499999999999997780. Equality missed that, so those two rows fell out in numeric\n order — `slow` before `fast`, once, in the middle of a file that was otherwise right.\n\n Two rows are at one time exactly when they carry the same `time_s`, which is the only\n definition a reader of the CSV can apply. The numeric pre-filter keeps the common case\n to one comparison; formatting happens only for candidates already within a hair.\n */\n let earliestText: string | null = null;\n /*\n Formatted on the first near-tie and not before, which on a single-rate table is never.\n\n The group and sample that set `earliest` are captured above rather than searched for\n again, since the loop below advances cursors as it goes and a later search would be\n looking at a table that had already moved on.\n */\n const asWritten = (): string =>\n (earliestText ??= open[source]?.formatTime(recordStart, sourceSample) ?? '');\n due.length = 0;\n for (let g = 0; g < open.length; g++) {\n const entry = open[g];\n if (!entry) continue;\n const sample = cursors[g] ?? 0;\n if (sample >= entry.group.samplesPerRecord) continue;\n const time = recordStart + sample / entry.group.rate;\n if (time !== earliest) {\n // Far away in the ordinary case; only a near-tie is worth formatting.\n if (!nearlyEqual(time, earliest)) continue;\n if (entry.formatTime(recordStart, sample) !== asWritten()) continue;\n }\n cursors[g] = sample + 1;\n // Same window rule as the wide layout, with the same per-rate slack.\n if (\n !sampleTimeIsInRange(earliest, range.startSeconds, range.endSeconds, toleranceFor(entry.group.rate))\n ) {\n continue;\n }\n for (let c = 0; c < entry.group.channels.length; c++) {\n due.push({ entry, groupIndex: g, sample, channel: c });\n }\n }\n if (due.length === 0) continue;\n if (due.length > 1) {\n due.sort(\n (a, b) =>\n (a.entry.group.channels[a.channel]?.signal.index ?? 0) -\n (b.entry.group.channels[b.channel]?.signal.index ?? 0),\n );\n }\n\n for (const item of due) {\n const channel = item.entry.group.channels[item.channel];\n const format = item.entry.formatters[item.channel];\n if (!channel || !format) continue;\n if (writer.hungUp) return;\n writer.pushLine(\n `${item.entry.formatTime(recordStart, item.sample)},${escapeCsvField(channel.column)},` +\n `${format(file.sampleAt(batch, recordInBatch, channel.signal, item.sample))}`,\n );\n item.entry.rows++;\n // Flushed inside the record for the same reason the wide layout is; see there.\n if (writer.full) await writer.flush();\n }\n }\n}\n\nasync function streamSignalRows(\n file: EdfFile,\n plan: ConversionPlan,\n open: OpenGroup[],\n recordStarts: Float64Array | null,\n options: ConvertOptions,\n): Promise<WrittenFile[]> {\n const { startSeconds, endSeconds, startRecord, endRecord } = plan.range;\n const { recordDuration } = file.header;\n let recordsDone = 0;\n\n /*\n Every destination has hung up, so nothing formatted from here on could reach anyone.\n `--stdout | head -1` is the usual way to arrive here: the reader takes one line and\n closes the pipe while the conversion is still near the start of the recording.\n\n Stopping also makes the reported row count mean what it says — rows that reached the\n consumer, rather than rows the loop went on formatting into a discarded buffer.\n */\n const allHungUp = (): boolean => open.length > 0 && open.every((entry) => entry.writer.hungUp);\n\n for await (const batch of file.readRecords({ startRecord, endRecord })) {\n if (allHungUp()) break;\n for (let r = 0; r < batch.recordCount; r++) {\n if (allHungUp()) break;\n const index = batch.firstRecordIndex + r;\n const recordStart = recordStarts ? (recordStarts[index] ?? index * recordDuration) : index * recordDuration;\n\n if (plan.layout === 'long') {\n await writeLongRecord(file, open, batch, r, recordStart, plan.range);\n recordsDone++;\n continue;\n }\n\n for (const entry of open) {\n const { group, writer, formatters, formatTime } = entry;\n const { channels, rate } = group;\n // Slack that never reaches the next sample; see toleranceFor.\n const slack = toleranceFor(rate);\n\n for (let sample = 0; sample < group.samplesPerRecord; sample++) {\n const time = recordStart + sample / rate;\n if (!sampleTimeIsInRange(time, startSeconds, endSeconds, slack)) continue;\n\n let row = formatTime(recordStart, sample);\n for (let c = 0; c < channels.length; c++) {\n const channel = channels[c];\n const format = formatters[c];\n if (!channel || !format) continue;\n row += ',' + format(file.sampleAt(batch, r, channel.signal, sample));\n }\n if (writer.hungUp) break;\n writer.pushLine(row);\n entry.rows++;\n\n /*\n Flushed inside the record, not only at the end of one.\n\n The buffer was drained once per record, so the rows of a single record piled up\n with nothing emptying them — memory followed samples-per-record rather than the\n batch size the writer exists to hold to. One record of 16,000,000 samples died\n with a heap out of memory under a 256 MB cap, while the same 32 MB of samples\n split into 16,000 records converted to the same 283 MB CSV without trouble. The\n format allows either layout and says nothing about which to expect.\n\n `full` is a synchronous read of the pending size, so the twenty million rows that\n are not at a boundary cost a comparison rather than a microtask each.\n */\n if (writer.full) await writer.flush();\n }\n await writer.maybeFlush();\n }\n\n recordsDone++;\n }\n\n if (options.onProgress) {\n /*\n A caller's callback is the caller's, and its failures are not the destination's.\n\n This ran inside the same try that turns a stream failure into WRITE_FAILED, so a\n progress callback that threw came back as `Writing to \"out\" failed: caller bug`,\n advising the reader to check a destination that was working perfectly. It is the\n same misattribution the write hints had until 0.4.36, one layer up.\n\n The original is kept as `cause`, so the stack that actually matters survives, and\n the conversion still stops — the callback threw, and carrying on writing into a\n directory whose owner has just failed is not an improvement.\n */\n try {\n options.onProgress({\n recordsDone,\n recordsTotal: endRecord - startRecord,\n // Once per writer: the long layout's groups share one, so summing per group\n // reported a figure larger than the file being written.\n bytesWritten: [...new Set(open.map((entry) => entry.writer))].reduce(\n (sum, entry) => sum + entry.charsWritten,\n 0,\n ),\n });\n } catch (cause) {\n throw new ConversionError(\n 'CALLBACK_FAILED',\n `The onProgress callback threw: ${cause instanceof Error ? cause.message : String(cause)}`,\n 'This is the caller\\'s callback, not the recording or the destination. Whatever was ' +\n 'written before it threw is incomplete and should not be used.',\n { cause },\n );\n }\n }\n }\n\n const closed = new Set<BufferedLineWriter>();\n for (const entry of open) {\n if (closed.has(entry.writer)) continue;\n closed.add(entry.writer);\n try {\n await entry.writer.end();\n // With --gzip the writer's stream is the compressor, whose end callback fires when the\n // compressor is done rather than when the file behind it is. Awaiting only that would\n // report success with the tail of the file still in flight.\n await entry.settled;\n } finally {\n // In a finally for the reason 0.5.45 gives about the writer's own release: a\n // conversion that fails here still has to leave process.stdout as it found it, and a\n // failure is exactly when a caller goes on to convert something else.\n entry.release();\n }\n }\n\n // A shared table is one file, and its row count is every group's rows, not the first's.\n if (plan.layout === 'long') {\n const first = open[0];\n if (!first) return [];\n return [{ name: first.group.fileName, rows: open.reduce((sum, e) => sum + e.rows, 0) }];\n }\n return open.map((entry) => ({ name: entry.group.fileName, rows: entry.rows }));\n}\n\n/**\n * The stream rows are written to, plus a promise for the data reaching its destination.\n *\n * Compression sits between the writer and the file as a transform. Failures below it — a\n * full disk, an unwritable path — surface on the file stream, where nothing is listening,\n * so they are forwarded onto the compressor: that is the stream the writer watches, and\n * routing them there keeps one error path rather than two.\n */\nfunction compressed(\n target: Writable,\n gzip: boolean,\n): { stream: Writable; settled: Promise<void>; release: () => void } {\n if (!gzip) return { stream: target, settled: Promise.resolve(), release: (): void => {} };\n const compressor = createGzip();\n /*\n Removable, because one of the streams this can be handed outlives the conversion.\n\n 0.5.36 fixed exactly this leak for the writer's own listener: a library caller running\n twelve `toStdout` conversions left twelve 'error' listeners on `process.stdout` and got\n Node's MaxListenersExceededWarning on the eleventh. That fix is `BufferedLineWriter`'s\n `#release()`, and it cannot reach this one — under `gzip` the writer's stream is the\n compressor, and `process.stdout` is only ever the compressor's destination. So the same\n leak survived on the same stream, behind one extra flag, and the regression test written\n to catch it does not pass `gzip: true`.\n\n A file stream is a different matter and needs no release: it is created for this\n conversion and closed with it. The discipline is the writer's — release only from a\n stream this tool does not own.\n */\n const forward = (error: Error): void => {\n compressor.destroy(error);\n };\n target.on('error', forward);\n const release = (): void => {\n if (target === process.stdout || target === process.stderr) target.off('error', forward);\n };\n\n /*\n pipe() ends its destination when the source ends, and stdout must survive the\n conversion: the writer already refuses to close it, because a closed stdout breaks\n every later write in the process. Nothing waits on stdout either — it is not this\n tool's to finish.\n */\n const toStdout = target === process.stdout;\n compressor.pipe(target, { end: !toStdout });\n if (toStdout) {\n /*\n Waited on, even though stdout is not ours to end.\n\n This returned an already-resolved promise, so `await entry.settled` waited for nothing\n and the conversion declared itself finished while the compressor still held the tail of\n the stream. `--stdout --gzip` onto a destination that filled up therefore printed the\n ENOSPC *and then* \"Wrote 102,400 rows to stdout.\" — and exited 0, over a file 11,270\n bytes short whose gzip member has no trailer and will not decompress. Through `--out`,\n on the same volume with the same space, the identical failure is reported and exits 1.\n\n The byte audit could not see it either: it stats the descriptor as soon as the writers\n are done, which on this path is before the compressor has pushed its last chunks.\n\n `finished(compressor)` is the source side, not the destination — it resolves when the\n compressor has flushed everything into stdout, and it is stdout's own write that fails.\n That keeps `end: !toStdout` exactly as it was: nothing here closes stdout.\n */\n const flushed = finished(compressor).catch((error: unknown) => {\n /*\n EPIPE is not a failure here, and turning it into one is the trap this nearly fell\n into: `--stdout --gzip | head` is an ordinary thing to type, and the documented\n answer to it is \"Stopped: the reader closed the pipe after 52,507 of 102,400 rows\n had been written\", exit 0. Waiting on the compressor surfaced the EPIPE that the\n uncompressed path already routes through the writer's hang-up flag — the writer\n sees the same error, forwarded, and records it — so the wait has to let that one\n through and keep everything else.\n */\n if ((error as NodeJS.ErrnoException | null)?.code === 'EPIPE') return;\n throw error;\n });\n flushed.catch(() => {});\n return { stream: compressor, settled: flushed, release };\n }\n\n /*\n A failure under the compressor rejects both this promise and the writer's own end(),\n and end() is the one awaited first. Without a handler attached here that rejection\n belonged to nobody, and Node killed the process over it: `--gzip` into an unwritable\n path printed a raw EISDIR stack trace instead of the ordinary \"Writing to ... failed\"\n message and exit 1, which is what the same path does uncompressed.\n\n Attaching the handler is enough to make it handled. Awaiting `settled` downstream still\n reports the failure in the case where end() happened to succeed.\n */\n const settled = finished(target);\n settled.catch(() => {});\n return { stream: compressor, settled, release };\n}\n\n/**\n * Write one of the sidecar files, reporting a failure the way the signal writer does.\n *\n * These three used to call `writeFile` bare, so a failure escaped as whatever the\n * filesystem said — `EISDIR: illegal operation on a directory, open '...'` with no hint\n * and, more importantly, no mention that the signal files had already been written. The\n * conversion stopped half-done and the message gave no sign of it.\n */\nasync function writeOutputFile(\n outputDir: string,\n name: string,\n contents: string,\n gzip = false,\n bom = false,\n): Promise<void> {\n // metadata.json never gets one: JSON.parse rejects a leading U+FEFF, so a mark there\n // would break every reader of the file to help a spreadsheet that will not open it.\n if (bom) contents = UTF8_BOM + contents;\n try {\n // The sidecars are built in memory before being written, so compressing them in memory\n // costs nothing extra. Only the signal tables are large enough to need a stream.\n await writeFile(path.join(outputDir, name), gzip ? gzipSync(contents) : contents, gzip ? undefined : 'utf8');\n } catch (cause) {\n // The same as the signal tables above; see the note there.\n throw new ConversionError(\n 'WRITE_FAILED',\n `Writing \"${name}\" to \"${outputDir}\" failed: ${describeFsError(cause)}.`,\n writeHint(cause),\n );\n }\n}\n\nasync function writeChannelsCsv(\n outputDir: string,\n file: EdfFile,\n plan: ConversionPlan,\n gzip: boolean,\n bom: boolean,\n): Promise<WrittenFile> {\n const includedColumns = new Set(plan.groups.flatMap((g) => g.channels.map((c) => c.signal.index)));\n const fileFor = new Map<number, string>();\n for (const group of plan.groups) {\n for (const channel of group.channels) fileFor.set(channel.signal.index, group.fileName);\n }\n\n /*\n A rate rendered the way the file name beside it in the same row was rendered.\n\n `sampling_rate_hz` and `output_file` are two cells of one row about one rate, and they were\n written from different renderings of it — the cell from `String`, the name from\n `formatRates` over the whole set. They agree on every rate `String` prints plainly and part\n company on the ones it does not:\n\n a,0,a,uV,1e-19,100,...,signals_1_000e-19hz.csv,yes\n\n A reader joining that column against the files on disk finds `1e-19` naming\n `1_000e-19hz`, and `--info` printing a third thing again — except that `--info`'s RATE\n column is `1.000e-19 Hz`, which is the name's own form. channels.csv was the one surface\n rendering the rate for itself.\n\n Rendered together because that is how the names are: two rates a sixth decimal apart round\n to one string, and `formatRates` widens the whole set when they do, so a per-rate rendering\n would disagree with the names again on exactly those files.\n */\n const groupRates = plan.groups.map((group) => group.rate);\n const rateText = new Map<number, string>(\n formatRates(groupRates).map((text, i) => [groupRates[i] as number, text]),\n );\n\n const lines = [\n csvRow([\n 'column',\n 'signal_index',\n 'label',\n 'unit',\n 'sampling_rate_hz',\n 'samples_per_record',\n 'physical_min',\n 'physical_max',\n 'digital_min',\n 'digital_max',\n 'transducer',\n 'prefiltering',\n 'output_file',\n 'converted',\n ]),\n ];\n\n for (const signal of file.header.signals) {\n if (signal.isAnnotations) continue;\n const column = plan.columnNames.get(signal.index) ?? `signal_${signal.index}`;\n lines.push(\n csvRow([\n column,\n String(signal.index),\n signal.label,\n signal.physicalDimension,\n /*\n Plain decimal, at whatever magnitude the header declares.\n\n `String` switches to exponent notation below 1e-6 and above 1e21, which `plain`\n exists to undo — annotations.csv's two numeric columns were given it because \"an\n EDF+ TAL states its onset as ordinary decimal text, so a file saying `+0.0000001`\n came back as `1e-7` in a column whose every other cell is a plain decimal\", and\n `fixed` refuses the same form in signals.csv for the same reason: \"a reader parsing\n the column as decimal text has no reason to expect it.\" channels.csv was the third\n CSV and the one that kept it. A magnetometer calibrated to ±1e-16 T had its\n `physical_min` written `-1e-16` beside a `digital_min` of `-32768`, in the pair of\n columns this documentation points at for recovering the digital codes, over a\n signals.csv writing every one of those values out in full — and a channel calibrated\n to ±100 in the row above it, so the column held both notations at once.\n */\n // Nor the rate, which is rendered above against the names it has to match. Nor\n // samples_per_record, which is a count.\n rateText.get(signal.samplingRate) ?? formatRate(signal.samplingRate),\n String(signal.samplesPerRecord),\n plain(signal.physicalMin),\n plain(signal.physicalMax),\n plain(signal.digitalMin),\n plain(signal.digitalMax),\n signal.transducer,\n signal.prefiltering,\n fileFor.get(signal.index) ?? '',\n includedColumns.has(signal.index) ? 'yes' : 'no',\n ]),\n );\n }\n\n const name = outputCsvName('channels', gzip);\n await writeOutputFile(outputDir, name, lines.join('\\n') + '\\n', gzip, bom);\n return { name, rows: lines.length - 1 };\n}\n\n/*\n The bounds an annotation is filtered against: what the caller actually asked for, not the\n window that survived being clamped to the recording.\n\n Filtering by the resolved window meant an unbounded request still lost events. `--end 999h`\n on a three-second file clamps to 3, and `--start 0` gets its end from the recording, so\n both filtered to [0, 3) and dropped the markers at 3.0 and 3.5 that a bare invocation\n keeps — asking for more of a recording returned less of it.\n\n An end the caller did not give is unbounded, not \"the end of the data\": EDF+ lets an\n annotation sit past the last sample, which is exactly where an end-of-recording marker is.\n\n `--duration` is measured from wherever the conversion actually starts. Anchoring it at 0\n instead read the same absent `--start` two ways in two adjacent lines, and on a recording\n that does not begin at zero the two windows did not even overlap: an EDF+D file whose first\n record sits at 30 s converted its samples from [30, 35) while filtering annotations against\n (-inf, 5), so every event inside the converted window was dropped and `annotations.csv` came\n back empty. `resolveRange` has always defaulted the same missing start to the earliest\n record, which is where this now takes it from.\n*/\n/**\n * What the durations in the events that will actually be written look like.\n *\n * These two warnings were raised from the file-wide counts the decoder accumulates, while\n * `annotations.csv` is filtered to the requested window. A conversion of one second of a\n * recording therefore warned that \"1 annotation states a duration that is not a number, so\n * its duration_s cell is empty\" about an event two seconds outside it — naming a cell that is\n * not in the output — and `--strict` failed the run for it. There is no such value, no such\n * cell, and no such row.\n *\n * Taken from the events themselves, after the same filter the writer applies, so the count\n * and the sentence describe the same rows. An unreadable duration is carried on the event\n * because `duration: null` cannot say whether the file gave one; a negative duration needs no\n * flag, since the value is right there.\n */\nexport function durationDiagnostics(\n annotations: readonly Annotation[],\n window: { from: number; to: number },\n /*\n And the name the run writes that file under, which these sentences did not have.\n\n Both hints send the reader to `annotations.csv` to look at the rows they are about, and a\n `--gzip` run writes `annotations.csv.gz`. `emptyAnnotations` two functions down takes this\n for the same reason and has since 0.8.48 — \"`--info` named `annotations.csv` for a run that\n wrote `annotations.csv.gz`\" — and the four beside it were left naming a file that is not in\n the directory.\n */\n gzip = false,\n): Diagnostic[] {\n const written = annotations.filter((a) => a.onset >= window.from && a.onset < window.to);\n const eventsFile = outputCsvName('annotations', gzip);\n const diagnostics: Diagnostic[] = [];\n\n const negative = written.filter((a) => a.duration !== null && a.duration < 0).length;\n if (negative > 0) {\n const one = negative === 1;\n diagnostics.push({\n code: 'ANNOTATION_DECODE_FAILED',\n severity: 'warning',\n message:\n `${counted(negative, 'annotation')} state${one ? 's' : ''} a duration below zero, ` +\n `which is not a length of time.`,\n hint:\n `The value is written to ${eventsFile} as the file gave it. Adding it to onset_s ` +\n 'ends the event before it starts, so check these rows before using the durations.',\n });\n }\n\n const unreadable = written.filter((a) => a.durationUnreadable === true).length;\n if (unreadable > 0) {\n const one = unreadable === 1;\n diagnostics.push({\n code: 'ANNOTATION_DECODE_FAILED',\n severity: 'warning',\n message:\n `${counted(unreadable, 'annotation')} state${one ? 's' : ''} a duration that is ` +\n `not a number, so ${one ? 'its' : 'their'} duration_s cell is empty.`,\n hint:\n 'The onset and the description were read normally. An empty duration_s otherwise ' +\n 'means the file stated no duration, so these rows cannot be told apart from those.',\n });\n }\n\n return diagnostics;\n}\n\n/**\n * What the descriptions in the events that will actually be written look like.\n *\n * EDF's four free-text header fields have had two warnings about where they land since they\n * were written: `FORMULA_LABEL` for text a spreadsheet runs instead of reading, and\n * `NONPRINTABLE_LABEL` for bytes that drive a terminal. Both say the same thing about the\n * remedy — the text is written exactly as the file has it, because rewriting it would mean\n * the CSV no longer says what the recording says — and both exist so that the tool is not\n * silent about where it goes.\n *\n * `annotations.csv`'s `description` column is the same kind of text, out of the same file,\n * into the same spreadsheet, and nothing was said about it at all. An event described\n * `=HYPERLINK(\"http://…\",\"Sleep stage W\")` was written verbatim, exit 0, no warning, and\n * opens as a live link nobody in the reading chain wrote; one carrying `\\x1b[31m` turns the\n * terminal red on `cat annotations.csv`. It is the more likely of the two to happen by\n * accident, since a description is typed by a person at a scoring station while a channel\n * label is written once by the recorder.\n *\n * It is also the only free text in the output that can carry a character above U+00FF —\n * header text is decoded latin1, so every byte of it becomes a code point below U+0100, and\n * a bidirectional override cannot reach a label. It can reach a description, which is UTF-8.\n *\n * Counted rather than raised per event, unlike the header's four fields: a night's scoring is\n * thousands of events, and a warning each is not a report. The count is of the rows that\n * reach `annotations.csv`, after the same window filter the writer applies, for the reason\n * `durationDiagnostics` beside it gives.\n */\nexport function descriptionDiagnostics(\n annotations: readonly Annotation[],\n window: { from: number; to: number },\n /** The name the run writes the event list under; see `durationDiagnostics`. */\n gzip = false,\n): Diagnostic[] {\n const written = annotations.filter((a) => a.onset >= window.from && a.onset < window.to);\n const eventsFile = outputCsvName('annotations', gzip);\n const diagnostics: Diagnostic[] = [];\n\n const formulaic = written.filter((a) => startsFormula(a.text));\n if (formulaic.length > 0) {\n const one = formulaic.length === 1;\n const shown = [...new Set(formulaic.map((a) => a.text[0] as string))].join(', ');\n diagnostics.push({\n code: 'FORMULA_LABEL',\n severity: 'warning',\n message:\n `${counted(formulaic.length, 'annotation')} ${one ? 'has a description' : 'have descriptions'} ` +\n `starting with ${shown}, which Excel, LibreOffice and Google Sheets read as the start ` +\n `of a formula rather than as text.`,\n hint:\n `The text is written to ${eventsFile} exactly as the file has it, so the cell is ` +\n 'what the recording says. Open the CSV with pandas or R, or import it into the ' +\n 'spreadsheet as text, if you do not want it evaluated.',\n });\n }\n\n const marked = written.filter((a) => unprintableIn(a.text).length > 0);\n if (marked.length > 0) {\n const one = marked.length === 1;\n const shown = [...new Set(marked.flatMap((a) => unprintableIn(a.text)))]\n .map(escapeCharacter)\n .join(', ');\n diagnostics.push({\n code: 'NONPRINTABLE_LABEL',\n severity: 'warning',\n message:\n `${counted(marked.length, 'annotation')} ${one ? 'has a description' : 'have descriptions'} ` +\n `carrying text a terminal does not print as itself (${shown}), written to ` +\n `${eventsFile} exactly as the file has ${one ? 'it' : 'them'}.`,\n hint:\n 'A control byte can drive the terminal and a bidirectional override reverses what ' +\n 'follows it, so read the file with pandas or R rather than with cat. The cell is ' +\n 'what the recording says either way.',\n });\n }\n\n return diagnostics;\n}\n\n/**\n * The window annotations are filtered by — the bounds as asked for, not as snapped to records.\n *\n * Exported so `--info` can count the events a conversion would write using the same predicate\n * that writes them, rather than a second copy of it.\n */\nexport function requestedAnnotationWindow(\n options: ConvertOptions,\n recordingStart: number,\n): { from: number; to: number } {\n const from = options.start ?? -Infinity;\n const to =\n options.end !== undefined\n ? options.end\n : options.duration !== undefined\n ? (options.start ?? recordingStart) + options.duration\n : Infinity;\n return { from, to };\n}\n\nasync function writeAnnotationsCsv(\n outputDir: string,\n annotations: readonly Annotation[],\n window: { from: number; to: number },\n gzip: boolean,\n bom: boolean,\n): Promise<WrittenFile> {\n const inWindow = annotations\n .filter((a) => a.onset >= window.from && a.onset < window.to)\n .sort((a, b) => a.onset - b.onset || a.recordIndex - b.recordIndex);\n\n const lines = [csvRow(['onset_s', 'duration_s', 'description', 'record_index'])];\n for (const annotation of inWindow) {\n lines.push(\n csvRow([\n plain(annotation.onset),\n annotation.duration === null ? '' : plain(annotation.duration),\n annotation.text,\n String(annotation.recordIndex),\n ]),\n );\n }\n\n const name = outputCsvName('annotations', gzip);\n await writeOutputFile(outputDir, name, lines.join('\\n') + '\\n', gzip, bom);\n return { name, rows: inWindow.length };\n}\n\n/**\n * What to try next, chosen from what actually went wrong.\n *\n * Every write failure carried the same advice — \"Free up space or choose another destination\n * with --out\" — which fits exactly one errno. A directory sitting where signals.csv belongs\n * came back telling the reader to free up disk space, and so did a read-only volume, a\n * permission denial and a path too long for the filesystem. Wrong advice is worse than none:\n * it sends someone to check `df` on a disk that is fine, and the thing that is actually\n * wrong stays unexamined.\n *\n * The errno is the one piece of the failure that names the cause, so it is what picks the\n * sentence. Anything unrecognised keeps the general form rather than guessing.\n */\nfunction writeHint(cause: unknown, toStdout = false): string {\n /*\n The stdout path writes no files, and --out is the flag its user chose not to pass.\n\n Both halves of this sentence were wrong there: \"the files written so far\" named files\n that do not exist, and \"choose another destination with --out\" is advice for a different\n command — the destination is whatever the shell redirected the stream to. Same class as\n the disk-space hint this function replaced, one flag over.\n */\n const preamble = toStdout\n ? 'What reached stdout before it failed is incomplete and should not be used. '\n : 'The files written so far are incomplete and should not be used. ';\n return (\n preamble +\n destinationAdvice(\n cause,\n toStdout ? 'redirect it somewhere else' : 'choose another with --out',\n toStdout ? 'redirect it somewhere shorter' : 'choose a shorter destination with --out',\n 'Part of that path no longer exists; make sure nothing is removing it while the ' +\n 'conversion runs.',\n )\n );\n}\n\n/**\n * The same question asked before anything has been written: the output directory could not be\n * created.\n *\n * Both raisings carried one sentence for every errno — \"Check the path exists and that you\n * have permission to write there\" — which is the shape `writeHint` above was written to\n * replace, in the words of its own docstring: \"Wrong advice is worse than none: it sends\n * someone to check `df` on a disk that is fine, and the thing that is actually wrong stays\n * unexamined.\" A full disk, a read-only volume and a path past the filesystem's length limit\n * all got advice about a path that exists and a permission that is not the problem, two lines\n * under a message where `describeFsError` had already named the cause exactly.\n *\n * No preamble, because nothing has been written yet — which is the only thing that differs\n * between the two, so the sentences themselves are shared rather than copied.\n */\nfunction createHint(cause: unknown): string {\n return destinationAdvice(\n cause,\n 'choose another with --out',\n 'choose a shorter destination with --out',\n 'Part of that path cannot be created — a symbolic link with nothing behind it, or a ' +\n 'mount point that is not mounted; choose another with --out.',\n );\n}\n\n/** The sentence an errno earns, with the two phrases that name where \"somewhere else\" is. */\nfunction destinationAdvice(\n cause: unknown,\n elsewhere: string,\n shorter: string,\n missing: string,\n): string {\n const code = (cause as NodeJS.ErrnoException | null)?.code;\n switch (code) {\n case 'ENOSPC':\n return `The destination is out of space; free some up or ${elsewhere}.`;\n case 'EDQUOT':\n return `You are over your disk quota on this filesystem; ${elsewhere}.`;\n case 'EACCES':\n case 'EPERM':\n return `You do not have permission to write there; ${elsewhere}.`;\n case 'EROFS':\n return `That filesystem is mounted read-only; ${elsewhere}.`;\n case 'EISDIR':\n return `A directory is sitting where that file belongs; remove or rename it, or ${elsewhere}.`;\n /*\n The one errno whose sentence is not the same question at both call sites.\n\n Mid-conversion, a missing component is a directory that went away under a run that had\n already written into it, and \"make sure nothing is removing it\" is the thing to check.\n Before anything is written it is the opposite: the destination's parents are created\n recursively, so reaching ENOENT there means a component that cannot be created — a\n symbolic link with nothing behind it, or a mount point that is not mounted.\n\n $ edf2csv rec.edf --out /mnt/archive/out\n error: Cannot create \"/mnt/archive/out\": part of the path does not exist.\n Part of that path no longer exists; make sure nothing is removing it\n while the conversion runs.\n\n Nothing is removing it and nothing was there. `createHint`'s own docstring says the\n preamble \"is the only thing that differs between the two, so the sentences themselves\n are shared rather than copied\" — and this is the sentence where that was not so.\n */\n case 'ENOENT':\n return missing;\n case 'ENAMETOOLONG':\n return `That path is longer than the filesystem allows; ${shorter}.`;\n case 'EMFILE':\n case 'ENFILE':\n return `Too many files are open; a recording with many sampling rates opens one output file per rate, so --channels narrows it.`;\n case 'EPIPE':\n return 'Whatever was reading the output closed it before the conversion finished.';\n default:\n return 'Check the destination and run the conversion again.';\n }\n}\n\n/**\n * Confirms that everything handed to a file-backed stdout actually arrived.\n *\n * `edf2csv rec.edf --stdout > out.csv` onto a volume that the output very nearly fills lost\n * the tail in silence: 94,977 of 102,400 rows on disk, the file ending mid-row, stderr\n * announcing \"Wrote 102,400 rows to stdout.\" and the process exiting 0. The same recording\n * onto the same volume through `--out` fails correctly, which is what gives it away.\n *\n * POSIX `write` returns a short count rather than an error when the disk fills partway\n * through a single call, and only the NEXT write raises ENOSPC. `--out` always has a next\n * write — channels.csv and metadata.json come after — so it always finds out. `--stdout`\n * has nothing after it, and when fd 1 is a regular file Node's stdout is a SyncWriteStream\n * whose `_write` discards the byte count `writeSync` returns, so nothing is raised at all.\n * No error means no `#failure`, so checking that alone would not have caught this.\n *\n * What can be checked is the descriptor: how much it grew against how much it was given.\n * Only for a regular file — a pipe, a terminal or a socket has no size to compare, and on\n * those a short write cannot go unreported this way. Appending (`>>`) is fine, since the\n * starting size is taken before anything is written.\n *\n * Exported so `--info` can use the same audit a `--stdout` conversion does.\n *\n * `--info` wrote its description with `process.stdout.write` and looked at nothing: redirected\n * into a full filesystem it produced a zero-byte file and exited 0, so `edf2csv rec.edf --info\n * > desc.txt` reported success over nothing at all. A 900-channel recording's description is\n * 58 KB, which is not a size a destination is guaranteed to have.\n */\nexport function auditStdout(): { count: (bytes: number) => void; verify: () => void } | null {\n let startSize: number;\n try {\n const info = fstatSync(1);\n if (!info.isFile()) return null;\n startSize = info.size;\n } catch {\n // No usable descriptor to audit; the conversion is not the place to complain about it.\n return null;\n }\n\n let expected = 0;\n return {\n count: (bytes: number): void => {\n expected += bytes;\n },\n verify: (): void => {\n let landed: number;\n try {\n landed = fstatSync(1).size - startSize;\n } catch {\n return;\n }\n if (landed >= expected) return;\n\n /*\n This audit exists for the failure nothing else reports: a write that is accepted, and\n silently truncated. When the stream itself raised an error there is nothing left for\n it to add, and what it added was a second `error:` line denying the first —\n\n error: Writing to stdout failed: ENOSPC: no space left on device, write\n error: Writing to stdout failed: 58900 of 58900 bytes did not reach the destination,\n which stopped accepting them part way through.\n ... nothing after it raised an error because there was nothing after it.\n\n one failure, reported twice, the second of the two wrong about it.\n */\n if (process.stdout.errored) return;\n\n /*\n Nothing landing at all is not a short write, and was described as one.\n\n `--info > desc.txt` onto a full filesystem left a zero-byte file, and this said the\n destination \"stopped accepting them part way through\" and that \"what is there ends\n mid-row\" — of a file with nothing in it and no rows in it.\n */\n if (landed === 0) {\n throw new ConversionError(\n 'WRITE_FAILED',\n `Writing to stdout failed: none of the ${counted(expected, 'byte')} reached the destination.`,\n 'The destination is almost certainly out of space. Nothing was written, so there ' +\n 'is nothing there to discard.',\n );\n }\n throw new ConversionError(\n 'WRITE_FAILED',\n // The pair a reader subtracts by eye, so both go through the grouping — the rule\n // 0.8.5 set and reached only as far as the messages already built with `counted`.\n `Writing to stdout failed: ${grouped(expected - landed)} of ` +\n `${counted(expected, 'byte')} did not reach the destination, which stopped ` +\n `accepting them part way through.`,\n 'What is there ends mid-row and should not be used. The destination is almost ' +\n 'certainly out of space — a short write is how a filesystem reports filling up ' +\n 'mid-write, and nothing after it raised an error because there was nothing after it.',\n );\n },\n };\n}\n\n/**\n * Why `--stdout` cannot take this recording, or null when it can.\n *\n * Lifted out of the conversion so `--info` can ask the same question. It was not asking:\n * `--info --stdout` on a three-rate recording predicted \"Would write 1,155 rows, roughly\n * 22.2 KB\" and said the channels \"are written to one file per rate\" — for a command that\n * refuses to run, writes nothing, and names no files. `--info` exists to say what a\n * conversion will do, and this is one of the things it does.\n *\n * Reported by `--info` as a warning rather than a refusal, for the reason 0.5.51 gives about\n * the destination guards: `--info` writes nothing, so a rule about what the output would be\n * has no business stopping it from describing the recording — and being told the command\n * will not work is exactly what you asked.\n */\nexport function stdoutRefusal(file: EdfFile, plan: ConversionPlan): ConversionError | null {\n if (!plan.writeSignals) {\n return new ConversionError(\n 'UNSUPPORTED_REQUEST',\n '--stdout has no signal data to write because --annotations-only was given.',\n 'Drop one of the two flags.',\n );\n }\n\n /*\n No table at all is its own answer, and neither layout gave it.\n\n A recording with no signal channels — one holding only EDF+ annotations — produced\n zero rate groups. The wide layout then said \"--stdout needs exactly one table, but\n this recording produces 0, one for each sampling rate its channels use ()\", with an\n empty parenthetical, advice to narrow to one of no rates, and advice to use\n `--layout long` — which wrote zero bytes to stdout, not even a header row, and exited\n 0 while warning that \"the signal files hold their headers and no data\". There were no\n files and there was no header. The one path that was right about this is\n `--annotations-only`, which refuses outright, and this is the same situation reached\n by a different route.\n */\n if (plan.groups.length === 0) {\n return new ConversionError(\n 'UNSUPPORTED_REQUEST',\n file.dataSignals.length === 0\n ? `--stdout has no signal data to write: this recording has no signal channels, ` +\n `only ${file.header.isBdf ? 'BDF+' : 'EDF+'} annotations.`\n : '--stdout has no signal data to write: nothing was selected that carries samples.',\n file.dataSignals.length === 0\n ? /*\n Named the way that conversion would name it, since `--gzip` is already on the\n command line this is refusing. This hint is nothing but a command to run, and the\n command it names writes `annotations.csv.gz` — so a reader who follows it finds\n nothing under the name they were given. Same fault 0.8.48 fixed for the warnings,\n in the one refusal that names a file.\n */\n `Convert to a directory to get its ${outputCsvName('annotations', plan.gzip)}, or ` +\n `drop --stdout.`\n : 'Check --channels and the requested window, or convert to a directory instead.',\n );\n }\n\n // The long layout is one table whatever the rates are, so it has nothing to refuse.\n if (plan.layout !== 'long' && plan.groups.length !== 1) {\n return new ConversionError(\n 'UNSUPPORTED_REQUEST',\n // Naming the rates is the point: the hint says to narrow the selection, and this\n // is what there is to narrow it to. The parenthetical used to repeat the count\n // that had just been given — \"produces 3 (its channels use 3 different sampling\n // rates)\" — which told nobody anything they could act on.\n `--stdout needs exactly one table, but this recording produces ${grouped(plan.groups.length)}, ` +\n `one for each sampling rate its channels use ` +\n `(${listed(formatRates(plan.groups.map((g) => g.rate)).map((r) => `${r} Hz`))}).`,\n 'Narrow it to one rate with --channels, write --layout long to get them all in ' +\n 'one table, or convert to a directory instead.',\n );\n }\n return null;\n}\n\n\n\n/**\n * Asked for signal data and given none to put in a file.\n *\n * Every channel selected carries zero samples per record, so there is no table to make —\n * `edf2csv rec.edf --channels unused` writes channels.csv and metadata.json and no signals.csv\n * at all. The NO_SAMPLES warning explains the channel; nothing explained the missing file, and\n * the documentation says signals.csv is written unless --annotations-only was passed. Someone\n * looking for it should be told where it went.\n *\n * There are two ways to arrive with no groups, and one wording is only true of one of them. A\n * recording that holds nothing but EDF+ annotations has no channel that could have been\n * selected, its channels.csv is a header row and nothing else, and no channel of it carries\n * samples — so \"every channel selected\", \"channels.csv still describes them\" and \"which\n * channels do carry samples\" were three false statements in one warning, printed under a\n * warning that had just said the file has no signal channels.\n *\n * Exported, and worded in the present tense, so `--info` can raise the same one. It was built\n * inline here, which meant the one mode whose purpose is to say what a conversion will do said\n * nothing about the file that conversion would not write: `--info --strict` on a recording of\n * nothing but annotations reported one warning where converting it reported two, and\n * `--info --json` carried the shorter list to whatever reads it. Everything the answer depends\n * on is in the file and the plan, both of which `--info` already has.\n */\nexport function noSignalFile(file: EdfFile, plan: ConversionPlan): Diagnostic | null {\n if (!plan.writeSignals || plan.groups.length > 0) return null;\n const noChannelsAtAll = file.dataSignals.length === 0;\n return {\n code: 'NO_SAMPLES',\n severity: 'warning',\n message: noChannelsAtAll\n ? 'No signal file is written: there is no signal data in this recording to put in one.'\n : 'No signal file is written: every channel selected carries zero samples per data ' +\n 'record, so there is nothing to put in one.',\n // Named as they will be written. `plan.gzip` is on the plan because `--info` named\n // `annotations.csv` for a run that wrote `annotations.csv.gz`; these two sentences are\n // about the same pair of files and were still naming the uncompressed ones.\n hint: noChannelsAtAll\n ? `${outputCsvName('annotations', plan.gzip)} holds whatever events it carries. ` +\n `${outputCsvName('channels', plan.gzip)} lists signal channels, so it has none to list.`\n : // `--info` raises this too, since 0.7.84, and was told to run itself to answer it.\n // Naming where the number lives works in both modes; naming a command works in one.\n 'Nothing about them is lost: every channel\\'s samples per record is in the channel ' +\n `table --info prints, and in the ${outputCsvName('channels', plan.gzip)} a conversion writes.`,\n };\n}\n\n/**\n * The channels whose samples this run actually writes.\n *\n * `plan.columnNames` names every channel of the recording, because the names are derived from\n * the whole file rather than from the selection — so it is not the answer. The groups are:\n * `--channels` builds them out of what was selected, and a channel with no samples per record\n * has none to put in one either.\n */\nexport function convertedChannels(plan: ConversionPlan): Set<number> {\n return new Set(plan.groups.flatMap((group) => group.channels.map((c) => c.signal.index)));\n}\n\n/**\n * The signal table an `--annotations-only` run does not write, taken out of the hints about it.\n *\n * That mode writes the event list and nothing else — no signal files at all — and four hints\n * about record timing describe the rows of one. On a recording whose records run backwards it\n * printed both of these over an annotations.csv holding its header and no rows:\n *\n * warning: This is a discontinuous (EDF+D) recording: its data records are not\n * contiguous in time.\n * Each row carries its true recording time, so gaps stay visible instead of\n * being closed.\n * warning: 2 data records start earlier than the record before them.\n * Rows are written in file order, so the time column will not increase\n * monotonically.\n *\n * There are no rows and no time column. The facts above the hints are about the recording and\n * stay; what changes is the sentence describing what the conversion will do with them, which\n * is the same surgery `withTimingPromiseKept` does to the first of these when the record\n * starts cannot be derived.\n *\n * `writesSignals` rather than the option, because the plan is what settles it.\n */\nexport function withSignalTableUnwritten(\n diagnostics: readonly Diagnostic[],\n writesSignals: boolean,\n gzip: boolean,\n /*\n And the channels this run leaves out, which is the same question one channel at a time.\n\n `--annotations-only` writes no cells for any channel; `--channels` writes none for the\n ones it excludes, and the five sentences below are as untrue of those as they are of the\n whole run. `--info` prints `(not selected)` in the OUTPUT column for them and channels.csv\n records them with `converted: no`, and the warning three lines under the table said:\n\n 0 flat flat uV 4 Hz 0 to 0 (not selected)\n ...\n warning: Signal 0 (\"flat\") has digital minimum equal to digital maximum (0), so its\n values cannot be scaled.\n Its cells are left empty rather than filled with a value the header cannot\n justify.\n\n There are no cells. Under `--strict` that is a failed run over a channel this one does not\n touch. The rewrites are the same rewrites, so the set of them is the argument rather than\n a second copy: empty means no signal table at all, which is what `writesSignals` said.\n */\n converted: ReadonlySet<number> = new Set(),\n /*\n And whether this run writes the file those rewrites send the reader to.\n\n Every sentence below that takes a cell away offers channels.csv in its place — \"channels.csv\n still records the digital range the header gives\", \"it is named `signal_1` in channels.csv's\n column cell\". `--stdout` writes no sidecar at all, and it can be given `--channels`:\n\n $ edf2csv rec.edf --stdout --channels ECG > rows.csv\n warning: Signal 0 (\"flat\") has digital minimum equal to digital maximum (0), so its\n values cannot be scaled.\n No samples are converted for a channel --channels left out, so there are no\n cells to leave empty. channels.csv still records the digital range the\n header gives.\n\n It does not. The run writes one CSV to the stream and nothing else, so the file offered\n as the place the channel is still described is not written either — which is the same\n thing `withSidecarsNamed` says one pass later about the sentences it knows. These are the\n ones it has never been shown: they do not exist until this pass writes them.\n */\n toStdout = false,\n): Diagnostic[] {\n const skipped = (diagnostic: Diagnostic): boolean => {\n if (!writesSignals) return true;\n const named = /^Signal (\\d+)\\b/u.exec(diagnostic.message);\n return named !== null && !converted.has(Number(named[1]));\n };\n if (writesSignals && diagnostics.every((d) => !skipped(d))) return [...diagnostics];\n /*\n The sidecars named here are named as the run writes them.\n\n These sentences send the reader to the one file an `--annotations-only` run does write, and\n said `channels.csv` to a `--gzip` run that writes `channels.csv.gz` — five hints pointing at\n a name that is not in the directory, one of them beside the `_ch` collision hint that 0.8.48\n had already taught to say `channels.csv.gz`. So a single run named both spellings, and only\n the second one existed.\n */\n /*\n Named plainly under `--stdout`, where no compressed sidecar is written either.\n\n `--stdout --gzip` compresses the stream and nothing else, so `channels.csv.gz` is as\n absent as `channels.csv` — and it is the spelling `withSidecarsNamed` already uses one\n pass later when it says none is written.\n */\n const channelsFile = outputCsvName('channels', gzip && !toStdout);\n const annotationsFile = outputCsvName('annotations', gzip);\n /*\n What channels.csv still holds about the channel, or that there is no channels.csv.\n\n Worded the way the sidecar pass words the hints it rewrites — the file is named, so the\n reader knows what they are missing, and the command that produces it is named too.\n */\n const records = (what: string): string =>\n toStdout\n ? `--stdout writes no ${channelsFile}; a conversion to a directory records ${what}.`\n : `${channelsFile} still records ${what}.`;\n return diagnostics.map((diagnostic) => {\n if (!skipped(diagnostic)) return diagnostic;\n // The reason the cells are missing, which is the only part that differs between the two.\n const because = writesSignals ? 'for a channel --channels left out' : 'with --annotations-only';\n // The run-level sentences below are only reached when no signal table is written at all:\n // a selection leaves the rows alone, so nothing it excludes changes what the column says.\n const writes = '--annotations-only writes no signal rows';\n\n /*\n And the three calibration warnings, whose hints are about cells.\n\n Each describes what a conversion does with a channel whose header cannot map cleanly —\n leaves the cell empty, fills it with the one value the mapping has, keeps the inversion —\n and `--annotations-only` converts no samples, so none of it happens:\n\n warning: Signal 0 (\"flat\") has digital minimum equal to digital maximum (0), so its\n values cannot be scaled.\n Its cells are left empty rather than filled with a value the header cannot\n justify.\n\n What is wrong with the header is still worth saying, and channels.csv — which that run\n does write — still carries the calibration. One message also ends in the conversion:\n \"so every sample converts to the same value\", over a run converting none.\n */\n /*\n And the two that say where a channel's name lands, which is signals.csv in both layouts\n and neither of them here.\n\n `--annotations-only` writes no signal table at all, so the name reaches exactly one\n place: channels.csv's `column` cell, which that run does write — control bytes, `_ch`\n suffix and all. Both sentences sent the reader to a file that is not there:\n\n warning: Signal 0's label and unit contain 2 control characters (\\x1b), which will\n appear as the channel's name in signals.csv and in channels.csv's unit\n cell in any conversion that writes one ...\n warning: 2 signals share the label \"T8-P8\" (positions #0, #1).\n Their names are suffixed with the signal number so they stay\n distinguishable: a column name each in the wide layout, and a distinct\n value in the channel column under --layout long.\n\n Neither layout happens. The second sentence offers a choice between two files that are\n not written.\n */\n if (diagnostic.code === 'NONPRINTABLE_LABEL') {\n return {\n ...diagnostic,\n message: diagnostic.message\n /*\n The hedge goes where the file goes, so it is taken off wherever the header put it\n and folded into the clause below. A run writing into a directory does write\n channels.csv, and the qualification is noise there; a `--stdout` run writes none,\n which is the case the header's own sentence has been qualified for since 0.8.52.\n */\n .replace(' in any conversion that writes one', '')\n .replace(\n \"as the channel's name in signals.csv\",\n `as the channel's name in ${channelsFile}'s column cell` +\n `${toStdout ? ' in any conversion that writes one' : ''}`,\n )\n // Matched on the name the header diagnostic used, which the line above has not\n // touched: it renames the first mention, and this collapses the second.\n .replace(\"and in channels.csv's\", 'and in its'),\n };\n }\n /*\n And the channel that lost its own name, whose sentence ends in a column.\n\n plan.ts writes \"so its column is `X`\" for a run that writes a signal table and \"so it is\n named `X` in channels.csv's column cell\" for one that does not — decided by the run,\n because that is all it knows there. A selection decides it per channel: the rename still\n happens, since the names are derived from the whole file so that they agree with\n channels.csv and across runs, and the column it is named for is one this run has not got.\n */\n if (diagnostic.code === 'DUPLICATE_LABEL' && / so its column is \"/u.test(diagnostic.message)) {\n return {\n ...diagnostic,\n message: diagnostic.message.replace(\n / so its column is (\"[^\"]*\")\\.$/u,\n ` so it is named $1 in ${channelsFile}'s column cell` +\n `${toStdout ? ' in any conversion that writes one' : ''}.`,\n ),\n };\n }\n /*\n And the same sentence when the plan wrote it in this form to begin with.\n\n plan.ts decides between three nouns from the options it has — a column, the channel\n column of a long table, or a cell of channels.csv when no signal table is written at\n all — so under `--annotations-only` the sentence arrives already naming the cell, and\n the rewrite above, which matches the wide-layout form, never sees it. Which left the\n one form this pass could not touch as the one form carrying neither of the two things\n it knows: the hedge, and what `--stdout` calls that file.\n\n $ edf2csv montage.edf --info --stdout --gzip --annotations-only\n warning: Signal 2 is labelled \"T8_ch0\", ... so it is named \"T8_ch0_ch2\" in\n channels.csv.gz's column cell.\n Channel names are unique, and --stdout writes no channels.csv to look\n this channel up in by its signal_index — convert to a directory for that.\n\n One warning, one file, two spellings of it, and neither written by that run.\n */\n if (diagnostic.code === 'DUPLICATE_LABEL' && /'s column cell\\.$/u.test(diagnostic.message)) {\n return {\n ...diagnostic,\n message: diagnostic.message.replace(\n / in [\\w.]+'s column cell\\.$/u,\n ` in ${channelsFile}'s column cell` +\n `${toStdout ? ' in any conversion that writes one' : ''}.`,\n ),\n };\n }\n if (\n diagnostic.code === 'DUPLICATE_LABEL' &&\n diagnostic.hint?.startsWith('Their names are suffixed')\n ) {\n return {\n ...diagnostic,\n hint:\n 'Their names are suffixed with the signal number so they stay distinguishable. ' +\n (writesSignals\n ? toStdout\n ? `--channels left this channel out, and --stdout writes no ${channelsFile} for ` +\n `its suffixed name to appear in — convert to a directory for that.`\n : `--channels left this channel out, so its suffixed name appears in ` +\n `${channelsFile}'s column cell and nowhere else.`\n : toStdout\n ? // The one of the three this pass was extended without at 0.9.29. `--stdout`\n // writes no channels.csv either, and the report saying this goes on to say\n // so two warnings later — \"--stdout writes no channels.csv to look this\n // channel up in\" — so one run carried both sentences about one file.\n `--annotations-only writes no signal table, and --stdout writes no ` +\n `${channelsFile} for the suffixed names to appear in — convert to a ` +\n `directory for that.`\n : '--annotations-only writes no signal table, so the suffixed names appear ' +\n `only in ${channelsFile}'s column cells.`),\n };\n }\n /*\n And the channel with no label at all, whose sentence ends in a column too.\n\n `EMPTY_LABEL` says where the name this tool invents for it lands, and both of its forms\n land it in a signal table: \"It will appear as `signal_1`\", and, where some other channel\n really carries that label, \"so both columns are suffixed with their position instead\".\n A run writing no signal table puts the name in one place, which is the cell the two\n rewrites above already name.\n */\n if (diagnostic.code === 'EMPTY_LABEL') {\n // Hedged under `--stdout`, where the cell is in a file that run does not write — the\n // wording 0.8.52 gave the same clause in NONPRINTABLE_LABEL, for the same reason.\n // Spelled out as its own string rather than by appending an s to the singular, which\n // reads as a number of seconds to the check that keeps those going through\n // `plainSeconds` — and does so whether it is in code or in a comment about it.\n const hedge = toStdout ? ' in any conversion that writes one' : '';\n const cell = `${channelsFile}'s column cell${hedge}`;\n const cells = `${channelsFile}'s column cells${hedge}`;\n return {\n ...diagnostic,\n message: diagnostic.message\n .replace(/ It will appear as (\"[^\"]*\")\\.$/u, ` It is named $1 in ${cell}.`)\n .replace(\n 'so both columns are suffixed with their position instead.',\n `so both are suffixed with their position in ${cells} instead.`,\n ),\n };\n }\n /*\n And the fourth calibration warning, which the three above were rewritten without.\n\n `UNUSABLE_PHYSICAL_RANGE` ends in the same sentence they do — \"Its cells are left empty\n rather than filled with a value the header cannot justify\" — and needs a header no\n fixture has, a span that underflows to zero or one too large to represent, which is how\n it stayed out of the sweep that found the others.\n */\n if (diagnostic.code === 'UNUSABLE_PHYSICAL_RANGE') {\n return {\n ...diagnostic,\n hint:\n `No samples are converted ${because}, so there are no cells to leave empty. ` +\n `${records('the physical range the header gives')}`,\n };\n }\n if (diagnostic.code === 'DEGENERATE_DIGITAL_RANGE') {\n return {\n ...diagnostic,\n hint:\n `No samples are converted ${because}, so there are no cells to leave empty. ` +\n `${records('the digital range the header gives')}`,\n };\n }\n if (diagnostic.code === 'DEGENERATE_PHYSICAL_RANGE') {\n return {\n ...diagnostic,\n message: diagnostic.message.replace(\n 'so every sample converts to the same value.',\n 'so every sample would convert to the same value.',\n ),\n hint:\n `No samples are converted ${because}. ${records('the calibration, one point wide')}`,\n };\n }\n if (diagnostic.code === 'INVERTED_PHYSICAL_RANGE') {\n return {\n ...diagnostic,\n hint:\n `No samples are converted ${because}. ` +\n `${records('the physical minimum and maximum in the order the header gives them, inversion included')}`,\n };\n }\n /*\n And the record this one could not place, which is timed from its neighbours in a signal\n table and nowhere else. Its events are exported whatever its position is: an onset is\n read off the event, not off the record it sits in, and `record_index` still names that\n record.\n */\n if (\n diagnostic.hint?.startsWith('That record is timed as if') === true ||\n diagnostic.hint?.startsWith('Those records are timed as if') === true\n ) {\n const one = diagnostic.hint.startsWith('That record');\n return {\n ...diagnostic,\n hint:\n `${writes}, so nothing is timed from ${one ? 'that record' : 'those records'}. ` +\n `The events in ${one ? 'it' : 'them'} carry their own onsets, and ` +\n `${annotationsFile}'s record_index still names ${one ? 'it' : 'them'}.`,\n };\n }\n if (diagnostic.code !== 'DISCONTINUOUS' || diagnostic.hint === undefined) return diagnostic;\n if (diagnostic.hint.startsWith('Each row carries its true recording time')) {\n return {\n ...diagnostic,\n hint:\n `${writes}, so nothing here is timed from the ` +\n `records. ${annotationsFile} carries each event's own onset, and the record it ` +\n 'came from in record_index.',\n };\n }\n if (diagnostic.hint.startsWith('Rows are written in file order')) {\n return {\n ...diagnostic,\n hint:\n `${writes}, so no time column is affected. ` +\n `${annotationsFile}'s record_index still names the record each event came from.`,\n };\n }\n if (diagnostic.hint.startsWith('Sample times are written from zero')) {\n return {\n ...diagnostic,\n hint: `${writes}, so no sample times are written at all.`,\n };\n }\n /*\n And the three that say the times are written as if the records were contiguous, which\n this pass had not been shown.\n\n Those are the answers for a file whose record positions are not recorded, or are\n contradicted by its own `EDF+C` marker — and they describe a time column. An\n `--annotations-only` run writes none, so all three promise something about rows it does\n not write:\n\n warning: This file is marked continuous (EDF+C), but 1 of its 3 data records says\n it starts somewhere other than where continuity puts it.\n Times are written as if the records were contiguous, which is what EDF+C\n means. ...\n warning: This file is marked discontinuous but has no annotation channel, so where\n its records sit in time is not recorded anywhere.\n Times are written as if the records were contiguous. Any gaps are lost.\n\n over an annotations.csv holding its header and no rows. The three sentences above this\n one were amended for exactly this at 0.8.x; these were the DISCONTINUOUS hints that do\n not begin with any of their phrases.\n\n What the header says about itself is still worth saying, so the messages stay. Only the\n clause about what a conversion makes of it was false, and what is true instead is that\n the events carry their own onsets whatever the records do.\n */\n if (diagnostic.hint.startsWith('Times are written as if the records were contiguous')) {\n return {\n ...diagnostic,\n hint:\n `${writes}, so no times are written from the ` +\n `records at all. ${annotationsFile} carries each event's own onset, which the ` +\n 'records do not decide.',\n };\n }\n // The marker warning's hint, which `withTimingPromiseKept` has already rewritten once and\n // which points at the warning under it. That pointer is still right and is what separates\n // the two, so it is the clause about the time column that goes and not the sentence.\n if (diagnostic.hint.startsWith('Where its records sit in time is not recorded in this file')) {\n return {\n ...diagnostic,\n hint:\n 'Where its records sit in time is not recorded in this file, and ' +\n `${writes} to time from them anyway — see the ` +\n 'warning below.',\n };\n }\n return diagnostic;\n });\n}\n\n/**\n * The sidecar files a `--stdout` run does not write, taken out of the sentences about them.\n *\n * `--stdout` puts one table on the stream and writes nothing else — \"No sidecar files are\n * written\", as `ConvertOptions` puts it. Two diagnostics raised before the destination is\n * known end by pointing at one of those files:\n *\n * warning: The header's start date and time (\"XX.XX.XX\" and \"YY.YY.YY\") are not a date\n * and a time, so the recording has no start instant.\n * ... and metadata.json records start_datetime_local as null.\n *\n * warning: This recording's timekeeping annotations place it 1e17s from its own start\n * date ...\n * ... Add the onsets in annotations.csv to recover absolute times.\n *\n * Neither file exists after such a run. The second is advice a reader can follow into an\n * empty directory — there is no directory.\n *\n * Amended where the answer is, the same way `withTimingPromiseKept` rewrites a `DISCONTINUOUS`\n * hint the parser could not have known was false, and `withoutFileRateWarning` drops a header\n * diagnostic the plan supersedes. A conversion to a directory keeps every word.\n */\nexport function withSidecarsNamed(\n diagnostics: readonly Diagnostic[],\n { toStdout, gzip }: { toStdout: boolean; gzip: boolean },\n): Diagnostic[] {\n if (!toStdout && !gzip) return [...diagnostics];\n const channels = outputCsvName('channels', gzip);\n const annotations = outputCsvName('annotations', gzip);\n return diagnostics.map((diagnostic) => {\n /*\n The last message of this kind, and the one that names its files mid-sentence.\n\n `NONPRINTABLE_LABEL` says where an invisible byte lands — the channel's name in\n signals.csv, a cell of channels.csv — and `--gzip` writes neither of those names. It was\n left out of 0.8.48 because the file is named inside a sentence assembled from which of\n the four header fields carry bytes, and out of 0.8.54 for the same reason. Renaming is\n all it needs, once the sentence is settled: this runs after `withSignalTableUnwritten`\n has had its say about the layout, so whichever file the sentence ended up naming is the\n one that gets the suffix.\n */\n /*\n And the same sentence under `--stdout`, where the signal table has no name at all.\n\n The `channels.csv` half of it has been hedged since 0.8.52 — \"in the channels.csv of any\n conversion that writes one\", which is true of a run that writes none. The half naming\n `signals.csv` was not, and `--stdout` is the mode this warning matters most in: it is\n the one that really does print the CSV to a terminal, which is what the hint two lines\n under it warns about.\n\n $ edf2csv control-labels.edf --stdout | less\n warning: Signal 1's label contains 1 control character (\\x07), which will appear as\n the channel's name in signals.csv, exactly as the header has it.\n\n There is no signals.csv. The byte is in the header row going past on the stream, which\n is where the reader is looking.\n */\n if ((gzip || toStdout) && diagnostic.code === 'NONPRINTABLE_LABEL') {\n return {\n ...diagnostic,\n message: diagnostic.message\n // Past a name the pass above already suffixed: `channels.csv.gz` contains\n // `channels.csv`, and a second rename made it `channels.csv.gz.gz`.\n .replace(\n /\\bsignals\\.csv\\b(?!\\.gz)/gu,\n toStdout ? 'the CSV on stdout' : outputCsvName('signals', true),\n )\n .replace(/\\bchannels\\.csv\\b(?!\\.gz)/gu, channels),\n };\n }\n /*\n The header's own `NO_SAMPLES`, which names the file that describes the channel it is\n about — and under `--stdout` there is no such file, so the reassurance is empty:\n\n $ edf2csv one-empty-channel.edf --stdout > rows.csv\n warning: Signal 1 (\"unused\") carries no samples at all (0 per data record).\n It is described in channels.csv but left out of the converted data.\n\n Under `--gzip` the file is there under another name. Both are settled here.\n */\n if (diagnostic.code === 'NO_SAMPLES' && diagnostic.hint?.startsWith('It is described in')) {\n return {\n ...diagnostic,\n hint: toStdout\n ? 'It is left out of the converted data, and --stdout writes no channels.csv to ' +\n 'describe it in — convert to a directory for that.'\n : `It is described in ${channels} but left out of the converted data.`,\n };\n }\n /*\n And the other `NO_SAMPLES`, whose whole hint is the two files written instead.\n\n `noSignalFile` says where the signal data went for a recording that has none, and for\n the one shape of that — a file holding nothing but EDF+ annotations — the reassurance\n is a list of what the run does write. `--stdout` writes neither, and refuses the run\n outright, which the warning under it then says:\n\n $ edf2csv scoring.edf --info --stdout\n warning: No signal file is written: there is no signal data in this recording\n to put in one.\n annotations.csv holds whatever events it carries. channels.csv lists\n signal channels, so it has none to list.\n warning: --stdout would refuse this run: has no signal data to write: this\n recording has no signal channels, only EDF+ annotations.\n Convert to a directory to get its annotations.csv, or drop --stdout.\n\n Two consecutive warnings, the first offering the file the second says to convert to a\n directory to get. Named as the conversion that does write them, which is that advice.\n */\n if (\n toStdout &&\n diagnostic.code === 'NO_SAMPLES' &&\n diagnostic.hint?.includes('holds whatever events it carries') === true\n ) {\n return {\n ...diagnostic,\n hint:\n `--stdout writes neither: a conversion to a directory gets ${annotations} with ` +\n `whatever events this recording carries, and a ${channels} with no signal ` +\n 'channels to list.',\n };\n }\n /*\n The collision hint, whose whole advice is a file to look the channel up in.\n\n A duplicate label, or a label that collides with another channel's `_ch` suffix, renames\n the column — and the sentence saying so ends by sending the reader to channels.csv for\n the channel's `signal_index`, since the renamed name is the only one in the table:\n\n $ edf2csv montage.edf --stdout > rows.csv\n warning: Signal 2 is labelled \"T8_ch0\", which is also the column name another\n channel's \"_ch\" suffix produces, so its column is \"T8_ch0_ch2\".\n Column names are unique; look this channel up in channels.csv by its\n signal_index.\n\n There is no channels.csv, and the renamed column is sitting in the header row on stdout\n with nothing to map it back. Under `--gzip` it was worse: `channels.csv.gz`, a\n compressed file no `--stdout` run writes either.\n\n Answered the way the two hints above answer it — the file is named, so that the reader\n knows what they are missing, and the command that produces it is named too.\n */\n if (toStdout && diagnostic.code === 'DUPLICATE_LABEL' && diagnostic.hint?.includes('look this channel up in')) {\n // \"Channel names\" under --layout long, where the name lands in the channel column;\n // \"Column names\" in the wide layout. Both are true of the stream, so the half of the\n // sentence that is about the rename is kept as the plan wrote it.\n const unique = diagnostic.hint.startsWith('Channel names') ? 'Channel names' : 'Column names';\n return {\n ...diagnostic,\n hint:\n `${unique} are unique, and --stdout writes no channels.csv to look this channel ` +\n `up in by its signal_index — convert to a directory for that.`,\n };\n }\n if (\n toStdout &&\n diagnostic.code === 'START_TIME_UNREADABLE' &&\n diagnostic.hint?.includes('metadata.json records')\n ) {\n return {\n ...diagnostic,\n hint:\n 'time_s is unaffected — it counts from the start of the recording either way. What ' +\n 'cannot be done is turning it into a wall-clock instant, and --stdout writes no ' +\n 'metadata.json to record start_datetime_local as null in.',\n };\n }\n if (\n diagnostic.code === 'DISCONTINUOUS' &&\n diagnostic.hint?.includes('onsets in annotations.csv')\n ) {\n return {\n ...diagnostic,\n hint: toStdout\n ? 'Sample times are written from zero instead, so every row is present and the ' +\n 'column increases. The onsets that recover absolute times are in the annotation ' +\n 'channel; --stdout writes no annotations.csv, so convert to a directory for them.'\n : 'Sample times are written from zero instead, so every row is present and the ' +\n `column increases. Add the onsets in ${annotations} to recover absolute times if ` +\n 'you need them.',\n };\n }\n return diagnostic;\n });\n}\n\n/**\n * `--annotations-only` on a recording that has no annotations.\n *\n * Exported and present-tense for the same reason `noSignalFile` above is. `--info` prints an\n * accurate line about it in the report body — \"and no annotations.csv either, since this\n * recording has no annotation channel\" — and raised nothing, so the one mode whose purpose is\n * to say what a conversion will do carried a shorter warning list than the conversion did:\n * `--info --json --annotations-only` on a plain EDF file listed no warning where converting\n * lists one, and `--info --strict`, which cli-reference.md recommends for screening a folder\n * before converting it, exited 0 where the conversion exits 1. Same defect as the one 0.7.84\n * closed for `NO_SAMPLES`, one flag over; both halves of the answer are in the file and the\n * options, which `--info` already has.\n */\nexport function noAnnotations(file: EdfFile, options: ConvertOptions): Diagnostic | null {\n if (options.annotationsOnly !== true || file.annotationSignals.length > 0) return null;\n return {\n code: 'NO_ANNOTATIONS',\n severity: 'warning',\n message:\n '--annotations-only was requested but this recording has no annotation channel, ' +\n 'so there are no events to export.',\n /*\n The format the file is in, rather than the one most files are in.\n\n \"Plain EDF files carry no annotations\" was said to every recording that reaches here,\n and two kinds of file reach it that are not plain EDF. A BioSemi `.bdf` was told about a\n format it is not in — this tool tells EDF and BDF apart everywhere else, down to the\n `BDF Annotations` label the specification gives the channel.\n\n And a file whose header says `EDF+C` while carrying no annotation channel at all is not\n a file for which having no events is ordinary: EDF+ keeps its events in that channel and\n is required to have one. The sentence read as reassurance about a file that is malformed.\n */\n hint: file.header.isEdfPlus\n ? `The header marks this ${describeFormat(file.header)}, and that format keeps its ` +\n `events in an annotation channel this file does not have. Convert without ` +\n `--annotations-only to get the signals.`\n : `Plain ${file.header.isBdf ? 'BDF' : 'EDF'} files carry no annotations. Convert ` +\n `without --annotations-only to get the signals.`,\n };\n}\n\n/**\n * `--annotations-only` that wrote no events, and why.\n *\n * The two causes are told apart because the answers are different. A channel holding nothing\n * but timekeeping entries has nothing to export and never will; a window that excluded every\n * event is a thing the caller can change, and the commonest reason is reading the window off\n * a clock the recording does not use — `--start` and `--end` are on the recording's own, which\n * starts at zero unless `--info` shows a \"Timed from\" line.\n *\n * `NO_ANNOTATIONS` rather than a new code, since it is the same statement its other raising\n * makes — there are no events to export — about the same flag, and a code is matched on by\n * scripts that should not have to learn a second one for the same fact.\n */\nexport function emptyAnnotations(\n total: number,\n window: { from: number; to: number },\n gzip = false,\n): Diagnostic {\n const windowed = (window.from !== -Infinity || window.to !== Infinity) && total > 0;\n return {\n code: 'NO_ANNOTATIONS',\n severity: 'warning',\n message: windowed\n ? `None of this recording's ${counted(total, 'event')} fall inside the requested ` +\n `window, so ${outputCsvName('annotations', gzip)} holds its header and no rows.`\n : `This recording's annotation channel carries no events, so ` +\n `${outputCsvName('annotations', gzip)} holds its header and no rows.`,\n hint: windowed\n ? /*\n Which is a line --info prints only when there is something to say.\n\n `Timed from` appears when the first sample is somewhere other than 0s — that is what\n the line is for — so on a recording timed from zero, which is most of them, this sent\n the reader to a line that is not in the report. The one hint whose whole job is \"you\n may be using the wrong clock\", pointing at nothing, on exactly the files where the\n window and the clock are hardest to tell apart.\n */\n '--start and --end are read on the recording\\'s own clock, which starts at 0s unless ' +\n '--info shows a \"Timed from\" line, and an event is kept when its onset falls inside ' +\n 'the window.'\n : 'The channel holds only the timekeeping entries that say where each data record ' +\n 'sits, and those are never exported.',\n };\n}\n\n/** Raised when the input moved while it was being read. See where it is pushed. */\nfunction inputChanged(hadChecksum: boolean): Diagnostic {\n return {\n code: 'INPUT_CHANGED',\n severity: 'warning',\n message:\n 'The input changed while it was being converted, so this output covers the file as ' +\n 'it was when the conversion started, not as it is now.',\n hint: hadChecksum\n ? 'No checksum was recorded: the bytes that were converted are no longer there to ' +\n 'hash. Convert again once the recording is finished.'\n : 'Convert again once the recording is finished to pick up the rest.',\n };\n}\n\nasync function writeMetadata(\n outputDir: string,\n inputPath: string,\n file: EdfFile,\n plan: ConversionPlan,\n written: readonly WrittenFile[],\n annotationCount: number,\n /** Hash of the bytes that were converted, or null when it could not be vouched for. */\n checksum: string | null,\n /** Whether the record start times could be read; see withTimingPromiseKept. */\n timedFromRecords: boolean,\n /** Whether each CSV starts with a byte order mark; see the `bom` field below. */\n bom: boolean,\n): Promise<void> {\n const { header } = file;\n\n /*\n The file as it was when it was opened, not as it is now.\n\n Both of these used to come from re-opening the path once the CSVs were written, which\n describes whatever answers to that name by then rather than what was converted. A\n recording still being written grew from 2,000 records to 3,000 mid-conversion and\n metadata.json recorded `data_records: 2000` — correct, the CSV holds 2,000 — beside the\n byte count and SHA-256 of the 3,000-record file. The two halves of one provenance record\n described two different files, and the checksum covered bytes nobody had converted.\n Replacing the file at that path did the same thing more thoroughly.\n\n `file.fileSize` is the number every record count and window in this output was derived\n from, and the hash is taken over exactly those bytes through the descriptor already open\n on them, so the record describes one file throughout.\n */\n const metadata = {\n tool: { name: 'edf2csv', version: TOOL_VERSION },\n source: {\n path: path.resolve(inputPath),\n bytes: file.fileSize,\n modified: new Date(file.modifiedAtOpenMs).toISOString(),\n sha256: checksum,\n },\n recording: {\n format: describeFormat(header),\n version: header.version,\n patient_id: header.patientId,\n recording_id: header.recordingId,\n // Zone-less on purpose: EDF records local wall-clock digits and no timezone.\n start_datetime_local: formatWallClock(header.startDateTime),\n start_date_raw: header.startDateRaw,\n start_time_raw: header.startTimeRaw,\n data_records: file.recordCount,\n data_records_declared: header.declaredRecordCount,\n record_duration_seconds: header.recordDuration,\n duration_seconds: file.durationSeconds,\n signal_count: header.signalCount,\n annotation_channels: file.annotationSignals.length,\n },\n conversion: {\n converted_at: new Date().toISOString(),\n start_seconds: plan.range.startSeconds,\n end_seconds: plan.range.endSeconds,\n whole_recording: plan.range.isWholeRecording,\n records_converted: [plan.range.startRecord, plan.range.endRecord],\n annotations_written: annotationCount,\n /*\n Which shape the signal table is in, which nothing recorded.\n\n A wide `signals.csv` and a long one are different files with different columns, and\n metadata.json described them identically — so a pipeline handed an output directory\n could not tell from the archive which it had. It matters most for `rate_groups` right\n below: in the wide layout those entries are one per file and their `channels` are that\n file's columns, and in the long layout every entry names the one shared table and its\n `channels` are values in that table's `channel` column. Same array, two readings, and\n no way to know which applied.\n */\n layout: plan.layout,\n /*\n The one option whose effect nothing else in this archive shows.\n\n `layout` is recorded on the stated grounds that \"the two have different columns and\n nothing else in the archive distinguishes them\". `--gzip` distinguishes itself: the\n names in `files` end `.csv.gz`. `--bom` puts three bytes in front of every CSV and\n leaves no other trace — and it is the option that decides whether reading the table\n back works. `csv.ts` sets out why: pandas strips the mark either engine, and Python's\n own `csv.reader` over a plain `open()` does not, nor does `readFileSync(path,\n 'utf8')`, so the first column name comes back as `\\ufefftime_s` and a lookup of\n `time_s` misses. A pipeline reading this document to find out how to open the files\n could not find out the one thing that changes the answer.\n */\n bom,\n files: written.map((f) => ({ name: f.name, rows: f.rows })),\n rate_groups: plan.groups.map((g) => ({\n file: g.fileName,\n sampling_rate_hz: g.rate,\n channels: g.channels.map((c) => c.column),\n decimals: g.channels.map((c) => c.decimals),\n })),\n },\n notes: withSidecarsNamed(\n withSignalTableUnwritten(\n [\n ...withTimingPromiseKept(withoutFileRateWarning(file.diagnostics), timedFromRecords),\n ...plan.diagnostics,\n ],\n plan.writeSignals,\n plan.gzip,\n convertedChannels(plan),\n ),\n // metadata.json is only written into a directory, so this is never the stdout case.\n { toStdout: false, gzip: plan.gzip },\n ).map((d) => ({\n code: d.code,\n severity: d.severity,\n message: d.message,\n })),\n };\n\n // Escaped like the two --json documents: metadata.json records the input's path, and a\n // `cat` of it should not be able to reorder the terminal. See escapeJsonText.\n const document = escapeJsonText(JSON.stringify(metadata, null, 2));\n await writeOutputFile(outputDir, 'metadata.json', `${document}\\n`);\n}\n\n\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edf2csv",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.38",
|
|
4
4
|
"description": "Convert EDF, EDF+ and BDF biosignal recordings (European Data Format) to CSV from the command line. Local, streaming, and never resamples or alters units.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"edf",
|