NAME

File::Raw::Archive::Writer - Archive entry emitter

SYNOPSIS

my $w = File::Raw::Archive->create("out.tar.gz",
    compression => 'gzip', level => 9);
$w->add(name => 'README',  content => $readme, mode => 0644);
$w->add(name => 'src/');                       # directory
$w->add(name => 'src/main.c', content => $main_c);
$w->close;

DESCRIPTION

A File::Raw::Archive::Writer is returned by "create" in File::Raw::Archive. It appends entries to an open archive file one at a time.

METHODS

add(name => $name, %fields)

Append one entry to the archive. Returns true. The entry type is inferred automatically from name and link_target when type is not supplied: a trailing / in name gives AE_DIR; a link_target gives AE_SYMLINK; everything else is AE_FILE.

Recognised fields:

name

Entry path as it should appear inside the archive. Required. A trailing / marks a directory.

content

Byte string payload. May be omitted for directories and symlinks. When size is not given it defaults to length($content).

type

Integer entry type constant. Normally inferred; supply explicitly to emit hardlinks (AE_HARDLINK) or device nodes (AE_FIFO, AE_CHAR, AE_BLOCK).

mode

POSIX permission bits. Defaults to 0755 for directories, 0777 for symlinks, and 0644 for all other types.

mtime

Last-modification time as integer Unix seconds, or a floating-point value to encode sub-second precision (e.g. 1_700_000_000.5).

mtime_ns

Nanosecond component of the modification time. Ignored when mtime is already a floating-point value.

uid / gid

Numeric owner and group IDs. Default 0.

Symlink or hardlink destination path. Setting this field implies type => AE_SYMLINK unless type is given explicitly.

xattrs

Hashref of name => bytes pairs emitted as PAX SCHILY.xattr.* records. Binary values are base64-encoded automatically when the format requires it.

close

Finalise the archive - for tar, writes the two mandatory trailing zero-filled 512-byte blocks - and release all resources. Idempotent; called automatically by DESTROY if the caller forgets.

SEE ALSO

File::Raw::Archive, File::Raw::Archive::Entry.

AUTHOR

LNATION <email@lnation.org>

LICENSE AND COPYRIGHT

This software is Copyright (c) 2026 by LNATION <email@lnation.org>.

This is free software, licensed under the Artistic License 2.0 (GPL Compatible).