No description
  • C 98.7%
  • Makefile 1.3%
Find a file
2025-11-29 07:22:54 -08:00
LICENSE Initial commit 2025-09-23 22:42:27 -07:00
Makefile test apps added, bugs fixed 2025-09-24 18:08:39 -07:00
README.md Update README.md 2025-09-25 18:52:31 -07:00
zerotar.h license added 2025-11-29 07:22:54 -08:00
zt_list.c license added 2025-11-29 07:22:54 -08:00
zt_untar.c license added 2025-11-29 07:22:54 -08:00

zerotar

Streaming tar processor for embedded systems

Features

zerotar is a minimal, streaming TAR parser for embedded systems with extremely low RAM. It is designed to parse a TAR archive incrementally without allocating large buffers.

  • Single API call for streaming parsing
  • Works with partial buffers
  • Very low memory footprint
  • Supports optional path flattening (ZEROTAR_FLAGS_FLATTEN)
  • Handles USTAR-formatted tar headers
  • Only core features supported:
    • filename
    • size
  • All other fields are skipped (no permissions, owners, etc)

Notes

  • The parser assumes extremely low memory environments, less than 200 bytes of RAM needed
  • The parser expects USTAR headers. Malformed headers may be ignored or cause early termination.
  • Always zero out struct zerotar_s before use to ensure proper operation.

Usage

Include

Include the header in your project:

#include "zerotar.h"

In one source file, define the implementation:

#define ZEROTAR_IMPLEMENTATION
#include "zerotar.h"

Initialization

Before use, all fields in struct zerotar_s should be zeroed:

struct zerotar_s zt = {0};
zt.flags = ZEROTAR_FLAGS_FLATTEN; // optional feature
zt.f_open  = my_open_callback;
zt.f_write = my_write_callback;
zt.f_close = my_close_callback;
zt.userdata = my_context;

Note: Callbacks can be NULL in case we don't need some or all of them.

Callbacks

f_open(void *userdata, const char *name, int size)

   Called when a new file starts. name is the file path (flattened if ZEROTAR_FLAGS_FLATTEN is set). size is the expected file size in bytes.

f_write(void *userdata, uint8_t *buf, int len)

   Called with chunks of file data. The parser may deliver data in arbitrary chunk sizes.

f_close(void *userdata)

   Called when a file finishes.

API

void zerotar(struct zerotar_s *zt, uint8_t *buf, int len);

   zt pointer to the parser state

   buf buffer containing part of the TAR archive

   len number of bytes in the buffer (if len < 0, the parser is reset and internal state cleared)

Call zerotar() repeatedly as new data arrives.