Skip to content

nqdchunk(3)

nqdchunk, nqdpiece — digests of the chunks of a large file, and a piece checked alone

libnqd, -lnqd -lnoqtis

#include <nqd.h>

int
nqdchunk(const char *dir, const char *path, uint64_t chunk, char *out, size_t cap, size_t *outlen, char *why, size_t wcap);

int
nqdpiece(const char *elem, size_t n, const char *piece, uint64_t off, nqdrep **rep);

() reads the file path in dir once and writes to out a ‘chunks’ element (noqtis-data(5)) in canonical JSON, for nqdput(3): its path, its size, the chunk size chunk (1024 to 2^30 bytes) and the SHA-256 of each run of chunk bytes, the last run short. The file is not split. out and outlen are as for nqdjson(3).

() checks the file piece, which holds the bytes of the element's file from byte off on (a multiple of the chunk size, at most the size), against the ‘chunks’ element elem (n bytes): each whole chunk in it, and a short last one when the piece ends where the file does. Only the piece is read. The report's ‘chunk’ rows name each chunk that differs, with its bytes (20 at most, then a count), or say which chunks and bytes match; a short run at the end of a piece that is not the end of the file is not checked, and a row says so.

A capsule's seal covers the digests through its data record, so nqchkx(3) with only set to noqtis.data.json checks them without the file. nqdchk(3) checks each recorded file whole against its chunks.

nqdchunk(): NQOK; NQEARG for a chunk size out of bounds or a path a capsule cannot hold; NQEIO when the file cannot be read; NQELIM when the digests would not fit in a record (64 MiB: take larger chunks); NQEBUF for a cap too small.

nqdpiece(): NQOK when every chunk read matches and there was at least one (or the file is empty); NQEVRFY otherwise, also for an element that is not valid; *rep is set in both cases (nqdchk(3)). NQEARG for a NULL argument.

noqtis-chunk(1), nqdchk(3), nqdnew(3), noqtis-data(5)