Skip to main content

Module reader

Module reader 

Source
Expand description

§Endianness

PSD is big-endian. Upstream calls DataView.getInt16/getUint16/getInt32/ getUint32/getFloat32/getFloat64 with the littleEndian argument either omitted or explicitly false (e.g. getInt16(off, false)), which means big-endian. The few *LE variants pass true. This port reproduces that: all default readers use from_be_bytes, the _le variants use from_le_bytes.

§Error strategy

Upstream throws Error in a handful of places (checkSignature, readSection overflow, warnOrThrow when strict, the >100MB guard in readBytes). It also reads past the end of a slice in some “broken file” recovery paths. We model fallible operations as Result<T, ReadError> with a small crate-local ReadError enum, returned consistently from every primitive that can fail. This is preferred over panicking because callers (the future document orchestration) need to distinguish recoverable from fatal conditions, mirroring upstream’s strict/warnOrThrow split.

Structs§

DecodeTarget
Pixel storage backing a PixelData during decode, tracking bit depth so the channel codecs can write at the correct stride.
PsdReader
Состояние низкоуровневого ридера (зеркало TS interface PsdReader extends ReadOptions).

Enums§

ReadError
Ошибки низкоуровневого ридера (зеркало throw new Error(...) из upstream).

Functions§

check_signature
Зеркало checkSignature(reader, a, b?).
peek_uint8
Зеркало peekUint8 — читает без сдвига курсора.
peek_uint32
Хелпер peekUint32 — задача упоминает его наличие; в upstream отдельной функции нет, но peek-семантика (чтение без сдвига курсора) полезна и согласуется с peekUint8. Big-endian.
read_ascii_string
Зеркало readAsciiString(reader, length).
read_bytes
Зеркало readBytes(reader, length).
read_bytes_slice
Zero-copy вариант чтения байтов: возвращает под-срез исходного буфера.
read_color
Consolidated readColor. NOTE (see report): effects_helpers, image_resources, additional_info::adjustment_keys, and additional_info::misc_keys each keep a LOCAL copy of this function (they cannot reach reader-internal helpers). Those should switch to this in a later cleanup task; not edited now.
read_data_raw
Mirror readDataRaw. Down-converts 16/32-bit samples to 8-bit (top byte).
read_data_rle
Mirror readDataRLE (PackBits). Writes one byte per sample to the 8-bit RGBA target. For >8 bit depths the source is still byte-stream PackBits, so we keep upstream’s byte semantics (the upstream RLE path also writes bytes).
read_data_zip
Mirror readDataZip (zlib via flate2).
read_fixed_point32
Зеркало readFixedPoint32 — 32-битное число с фиксированной точкой 16.16.
read_fixed_point_path32
Зеркало readFixedPointPath32 — 32-битное число с фиксированной точкой 8.24.
read_float32
read_float64
read_int8
Upstream имеет readInt8? Нет отдельной функции, но задание просит её — реализуем через интерпретацию байта как знакового (DataView.getInt8).
read_int16
read_int32
read_int32_le
Зеркало readInt32LE (little-endian).
read_pascal_string
Зеркало readPascalString(reader, padTo).
read_pattern
Consolidated readPattern. NOTE (see report): abr.rs and smart_object_keys.rs hold local copies; they should switch to this later.
read_psd
High-level entry point. Mirror of upstream readPsd(reader, readOptions), but takes a byte slice + options and builds a PsdReader internally.
read_psd_from_reader
Mirror of upstream readPsd operating on an existing reader (options must already be set on the reader, as upstream does via Object.assign).
read_section
Зеркало readSection<T>(reader, round, func, skipEmpty = true, eightBytes = false).
read_short_string
Зеркало приватной readShortString(reader, length).
read_signature
Зеркало readSignature(reader) — 4-байтовая подпись.
read_uint8
read_uint16
read_uint32
read_uint16_le
Зеркало readUint16LE (little-endian).
read_unicode_string
Зеркало readUnicodeString(reader) — uint32 длина (в code unit’ах), затем строка.
read_unicode_string_with_length
Зеркало readUnicodeStringWithLength(reader, length) (big-endian uint16 code units).
read_unicode_string_with_length_le
Зеркало readUnicodeStringWithLengthLE (little-endian uint16 code units).
skip_bytes
Зеркало skipBytes(reader, count).
valid_signature_at
Зеркало validSignatureAt(reader, offset)8BIM/8B64 по абсолютному offset.
warn_or_throw
Зеркало warnOrThrow(reader, message).

Type Aliases§

ReadResult
Результат операций ридера.