API
Public
load / save from FileIO.jl. #26
Private
ASDF.block_magic_token — Constant
block_magic_tokenThe 4-byte sentinel UInt8[0xd3, 0x42, 0x4c, 0x4b].
ASDF.host_byteorder — Constant
host_byteorderNative byte order of the running machine, detected at load time. Defined by ASDF.Byteorder.
ASDF.ASDFFile — Type
ASDFFileThe in-memory representation of a loaded ASDF file, combining the parsed YAML metadata tree with the binary block infrastructure needed to lazily materialize any array data it references.
Fields
| Field | Description |
|---|---|
filename | Path of the file on disk, as passed to ASDF.load_file. Used for display and diagnostics only. The file is not kept open after loading. |
metadata | The fully parsed YAML tree. Keys are strings matching the top-level YAML keys. Values may be any Julia type produced by the YAML constructors, including ASDF.NDArray, ASDF.ChunkedNDArray, nested Dicts, Vectors, and scalars. |
lazy_block_headers | All binary block headers found in the file, scanned once at load time. Shared by reference with every ASDF.NDArray in metadata, allowing them to locate and read their backing blocks on demand. |
ASDF.ASDFLibrary — Type
ASDFLibrarySoftware provenance metadata, serialized as a !core/software-1.0.0 YAML tag. [ASDF.write_file] inserts an entry automatically under the key "asdf/library" if one is not already present, using the package's own name, author, homepage, and version.
ASDF.BlockHeader — Type
BlockHeaderParsed representation of a single ASDF binary block header.
Every binary block in an ASDF file begins with a fixed-layout header that describes the block's compression, size, and integrity checksum. BlockHeader captures all decoded fields from that header, together with the IO handle and file position needed to subsequently read the block's data payload.
Fields
| Field | Description |
|---|---|
io | The open file handle from which the block's data can be read. |
position | Absolute byte offset of the block magic token within io. |
token | 4-byte magic token. Always equal to block_magic_token (\323BLK). |
header_size | Size of the extended header region in bytes (excludes the 6-byte prefix). |
flags | Block flags. Bit 0 (0x1) indicates a streamed block (not currently supported). |
compression | 4-byte compression key (e.g. "zstd", "bzp2"). |
allocated_size | Number of bytes allocated in the file for this block's data (≥ used_size). |
used_size | Number of bytes of (compressed) data actually written. |
data_size | Number of bytes of the uncompressed data. |
checksum | 16-byte MD5 digest of the compressed data, or all zeros if omitted. |
validate_checksum | When true, ASDF.read_block verifies the MD5 digest before returning data. |
File layout
The block occupies the following byte range within io, starting at position:
[position] | 4 bytes | magic token |
[position + 4] | 2 bytes | header_size (big-endian UInt16) |
[position + 6] | header_size bytes | extended header fields |
[position + 6 + header_size] | allocated_size bytes | data payload |
The extended header (always 48 bytes in the current implementation) contains, in order: flags (4 B), compression (4 B), allocated_size (8 B), used_size (8 B), data_size (8 B), and checksum (16 B).
All multi-byte integers in the header are stored in big-endian byte order.
ASDF.Blocks — Type
BlocksModule-level accumulator that collects ASDF.NDArrayWrapper values and their corresponding file positions during a single call to ASDF.write_file.
Blocks acts as a two-phase write buffer. In the first phase, as the YAML tree is serialized, each non-inline ASDF.NDArrayWrapper appends itself to arrays and reserves a sequential source index. In the second phase, ASDF.write_file iterates over arrays, compresses and writes each block to disk, and records the resulting file offsets in positions. The finalized positions vector is then written as the ASDF block index at the end of the file.
A single instance of Blocks is held in the module-level constant ASDF.blocks. Because this global state is mutated by ASDF.write_file, concurrent calls to write_file from multiple threads will corrupt each other's block lists. Do not call write_file concurrently.
Fields
| Field | Description |
|---|---|
arrays | Ordered list of arrays to be written as binary blocks, accumulated during YAML serialisation. The position of each wrapper in this vector is its zero-based block source index. |
positions | Absolute byte offsets of each written block within the output file, populated during the block-writing phase of ASDF.write_file. positions[i] corresponds to arrays[i]. |
ASDF.Byteorder — Type
ASDF.ByteorderRepresents the byte order of array data stored in a block. Available variants:
Byteorder_little: Little-endianByteorder_big: Big-endian
ASDF.Byteorder — Method
ASDF.Byteorder(str::AbstractString)::ByteorderConvenience conversion for ASDF.Byteorder. Inverse of Base.string(byteorder::Byteorder).
Examples
julia> ASDF.Byteorder("little")
Byteorder_little::Byteorder = 0ASDF.ChunkedNDArray — Type
ChunkedNDArrayA logical N-dimensional array assembled from a collection of arbitrarily-positioned ASDF.NDArrayChunk tiles, each backed by its own binary block or inline data.
ChunkedNDArray is the in-memory representation of a !core/chunked-ndarray-1.X.Y YAML node. It defines the shape and element type of the full logical array, but defers all data access to the individual chunks. The full array is only allocated and populated when Base.getindex(ndarray::NDArray) is called.
Fields
| Field | Description |
|---|---|
shape | Dimensions of the full logical array in Python/C (row-major) order, outermost dimension first. All elements must be non-negative. The equivalent Julia shape is reverse(shape). |
datatype | Element type shared by all chunks. Convert to a Julia type with Type(datatype). |
chunks | Ordered collection of tiles that together populate the logical array. Tiles are written in iteration order when materializing. Later tiles overwrite earlier ones in any overlapping region. |
ASDF.Compression — Type
Identifies the compression algorithm used for a data block. Available variants:
| Scheme | 4-byte key | Backend | Description |
|---|---|---|---|
C_None | \0\0\0\0 | – | Fast I/O speed, no CPU overhead |
C_Blosc | blsc | ChunkCodecLibBlosc.jl | Multi-threaded, shuffle-aware, best with typed numeric arrays |
C_Blosc2 | bls2 | See Issue #49 | Like Blosc but supports more than 2 GB of data |
C_Bzip2 | bzp2 | ChunkCodecLibBzip2.jl | Good ratio, moderate speed (default) |
C_Lz4 (:block) | lz4\0 | ChunkCodecLibLz4.jl | Fastest decompression, Python-compatible |
C_Lz4 (:frame) | lz4\0 | ChunkCodecLibLz4.jl | LZ4 frame format for non-Python consumers |
C_Xz | xz\0\0 | CodecXz.jl | Highest compression ratio, slowest |
C_Zlib | zlib | ChunkCodecLibZlib.jl | Broad compatibility |
C_Zstd | zstd | ChunkCodecLibZstd.jl | Best ratio/speed trade-off |
ASDF.Datatype — Type
Maps ASDF datatype strings to Julia types. Note this is unrelated to Base.DataType. Defined mappings:
| ASDF string | Julia type |
|---|---|
bool8 | Bool |
int8 ... int128 | Int8 ... Int128 |
uint8 ... uint128 | UInt8 ... UInt128 |
float16 ... float64 | Float16 ... Float64 |
complex32 | Complex{Float16} |
complex64 | Complex{Float32} |
complex128 | Complex{Float64} |
ASDF.LazyBlockHeaders — Type
LazyBlockHeadersA mutable container holding the complete list of ASDF.BlockHeader values scanned from an ASDF file, shared by reference with every ASDF.NDArray and ASDF.ChunkedNDArray constructed during parsing.
Reference sharing
Every ASDF.NDArray created during parsing of a given file holds a reference to the same LazyBlockHeaders instance. When ndarray[] is called, it indexes into lazy_block_headers.block_headers using the array's zero-based source field:
header = ndarray.lazy_block_headers.block_headers[ndarray.source + 1]
data = ASDF.read_block(header)Because block_headers is populated after all NDArray objects are constructed, no array needs to be updated individually when block scanning completes. The shared mutable reference propagates the result automatically.
Mutability
LazyBlockHeaders is a mutable struct solely to allow block_headers to be assigned after construction. The field is written exactly once per file load, immediately after YAML.load within ASDF.load_file returns. It is never modified again during normal use. Treat it as effectively immutable after load_file returns.
ASDF.NDArray — Type
NDArrayA lazily-materialized N-dimensional array stored in an ASDF file, either as a binary block or inline within the ASDF file.
NDArray is the in-memory representation of an !core/ndarray-1.0.0 YAML node. It holds the array's shape, type, and layout metadata, but defers reading and decompressing block data until the array is explicitly materialized by calling Base.getindex(ndarray::NDArray).
Fields
| Field | Description |
|---|---|
lazy_block_headers | Reference to the file's block header list. Used to resolve source indices at materialization time. |
source | Zero-based index of the backing binary block, or nothing for inline arrays. |
data | In-memory array for inline data, or nothing for block-backed arrays. |
shape | Array dimensions in Python/C (row-major) order — outermost dimension first. The equivalent Julia shape is reverse(shape). |
datatype | Element type, as an ASDF.Datatype enum value. Convert to a Julia type with Type(datatype). |
byteorder | Byte order of the stored data (Byteorder_little or Byteorder_big). |
offset | Byte offset from the start of the block to the first array element. Non-negative. |
strides | Byte strides in Python/C (row-major) order. Must all be positive and length(strides) == length(shape). |
ASDF.NDArrayChunk — Type
NDArrayChunkA positioned tile within an ASDF.ChunkedNDArray, pairing an ASDF.NDArray with a zero-based origin that locates the tile in the parent array's coordinate space.
Fields
| Field | Description |
|---|---|
start | Zero-based origin of the tile in Python/C (row-major) order, outermost dimension first. All elements must be non-negative. length(start) must equal length(ndarray.strides). |
ndarray | The tile data, including its own shape, datatype, byte order, and backing block reference. |
ASDF.NDArrayWrapper — Type
NDArrayWrapperA write-side wrapper around a Julia array that carries compression and layout options. Used as the value type when building a document dict for ASDF.write_file.
| Parameter | Default | Description |
|---|---|---|
compression | C_Bzip2 | Applied compression scheme |
inline | false | Embed data in YAML instead of a binary block |
lz4_layout | :block | :block for Python-compatible chunked LZ4, :frame for LZ4 frame format |
ASDF.find_all_blocks — Function
find_all_blocks(io::IO, pos::Int64=Int64(0); validate_checksum::Bool)Scans an IO stream and returns all ASDF.BlockHeader values found.
ASDF.load_file — Method
load_file(filename::AbstractString; extensions = false, validate_checksum = true)Reads an ASDF file from disk.
| Parameter | Description |
|---|---|
filename | Path to the .asdf file |
extensions | When true, unknown YAML tags are parsed leniently (as maps, sequences, or scalars) instead of raising an error |
validate_checksum | When true, each block's MD5 checksum is verified against the stored value |
Block data is located lazily. Block headers are scanned after the YAML is parsed, and array data (ndarray) is read only when Base.getindex(ndarray::NDArray) is called, i.e., ndarray[].
The file handle opened by load_file is retained for the lifetime of the returned ASDF.ASDFFile so that block data can be read on demand. Do not move, truncate, or overwrite the source file while any ASDF.NDArray from it may still be accessed.
ASDF.read_block — Method
read_block(header::BlockHeader)Uses an ASDF.BlockHeader to read, verify, and decompress the data payload.
ASDF.read_block_header — Method
read_block_header(io::IO, position::Int64; validate_checksum::Bool)Constructs an ASDF.BlockHeader by parsing the file at a given offset.
ASDF.write_file — Method
write_file(filename::AbstractString, document::Dict{Any,Any})Writes an ASDF file to disk. document is a plain Dict whose values may include NDArrayWrapper instances. These are serialized as binary blocks with appropriate compression.
Layout of the output file:
- ASDF/YAML header (
#ASDF 1.0.0, #ASDF_STANDARD 1.2.0, %YAML 1.1) - YAML tree (
!core/asdf-1.1.0) - Binary blocks — one per
NDArrayWrapperthat hasinline == false - Block index (
#ASDF BLOCK INDEX)
Base.getindex — Method
Base.getindex(chunked_ndarray::ChunkedNDArray)Allocates a dense array of shape reverse(shape) and fills it by calling chunk.ndarray[] for each chunk, placing the result at the correct offset.
Base.getindex — Method
Base.getindex(ndarray::NDArray)Returns the fully materialized array. See ASDF.NDArray for definitions. When block-backed (source !== nothing), this reads and decompresses the block, applies offset and strides via a StridedViews.StridedView, reinterprets bytes to Type(datatype), and byte-swaps if byteorder != host_byteorder. The returned array satisfies:
size(result) == Tuple(reverse(ndarray.shape))
eltype(result) == Type(ndarray.datatype)
sizeof(eltype) .* strides(result) == Tuple(reverse(ndarray.strides))Base.string — Method
string(byteorder::Byteorder)::AbstractStringConvenience conversion for ASDF.Byteorder. Inverse of ASDF.Byteorder(str::AbstractString).
Examples
julia> string(ASDF.Byteorder_little)
"little"