The OpenD Programming Language

processTar

Low level tar file processor. You must pass it a TarFileHeader buffer as well as a size_t for context. Both must be initialized to all zeroes on first call, then not modified in between calls.

Each call must populate the dataBuffer with 512 bytes.

returns true if still work to do.

Please note that it currently only passes regular files, hard and soft links, and directories to your handler.

bool
processTar
(,,
const(ubyte)[] dataBuffer
,
scope void delegate
(,,,
const(ubyte)[] data
)
handleData
)

Examples

/+
	void main() {
		TarFileHeader tfh;
		long size;

		import std.stdio;
		ubyte[512] buffer;
		foreach(chunk; File("/home/me/test/pl.tar", "r").byChunk(buffer[])) {
			processTar(&tfh, &size, buffer[],
			(header, isNewFile, fileFinished, data) {
				if(isNewFile)
					writeln("**** " , header.filename, " ", header.size);
				write(cast(string) data);
				if(fileFinished)
					writeln("+++++++++++++++");

			});
		}
	}

	main();
+/

Meta

History

TarFileType.symLink and TarFileType.hardLink used to be skipped by this function. On March 24, 2023, it was changed to send them to your handleData delegate too. The data argument to your handler will have the target of the link. Check header.type to know if it is a hard link, symbolic link, directory, normal file, or other special type (which are still currently skipped, but future proof yourself by either skipping or handling them now).