openFits
function openFits(reader, options?): Promise<ReadHdusResult>;Defined in: hdu/read-hdus.ts:352
Walk every Header-Data Unit through a RandomAccessReader, reading only header blocks: each data unit is located and measured from its keywords then seeked past, never fetched, so a remote file is enumerated without materializing it and a later readImage cutout fetches only its region.
Sizing, classification, random-groups rejection, and the strict/lenient
contract are the same code as readHdus (the per-HDU body and the
parseHeader END detection are shared, not reimplemented), so for
well-formed FITS the enumerated HDUs are identical. On malformed or
truncated input both fail safe (dataSizeKnown: false, nothing unsafe
read), but the reported dataOffset and warnings can differ: with a
missing END, openFits caps the scan at maxHeaderBlocks blocks, while
the in-memory readHdus is bounded only by the buffer length. The sync
readHdus is unchanged for in-memory inputs.
With reader.size known, dataSizeKnown reflects whether the declared
data unit fits within it. With reader.size undefined (a source of
unknown length) the header-declared length is trusted, dataSizeKnown is
true on that basis alone, and an actually short source is caught by
readImage’s own truncation check, not here.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
reader |
RandomAccessReader |
options |
OpenFitsOptions |
Returns
Section titled “Returns”Promise<ReadHdusResult>
Example
Section titled “Example”const reader = new HttpRangeReader(url);const { hdus } = await openFits(reader);const tile = await readImage(hdus[0], reader, { region: { start: [4096, 4096], shape: [256, 256] },});FITS Standard v4.0 §3.3-3.4: primary HDU and extensions (random groups: §6)