File-Raw-Archive
view release on metacpan or search on metacpan
Makefile.PL view on Meta::CPAN
. ' -Wl,-soname,Archive.so';
}
elsif ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys') {
my $implib = 'blib/arch/auto/File/Raw/Archive/libArchive.dll.a';
$platform_args{LDDLFLAGS} = ($Config{lddlflags} || '')
. ' -Wl,--export-all-symbols'
. " -Wl,--out-implib=$implib";
}
# zlib for gzip composition (we talk to libz directly for the
# streaming inflater). On Windows, also publish our own import library
# via set_libs so sister archive plugins (File::Raw::Archive::Zip,
# ::Cpio, ::Ar) get -L/-lArchive automatically when they
# ExtUtils::Depends->new(..., 'File::Raw::Archive').
{
my $libs = '-lz';
if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys') {
my $arch = $Config{installsitearch};
$libs .= qq{ -L"$arch/auto/File/Raw/Archive" -lArchive};
}
$pkg->set_libs($libs);
/*
* arch_io.c - registry + byte source/sink implementations.
*
* Mirrors the same shape File::Raw uses for file_plugin.h: a small
* static array of registered plugins, lookup by name, probe-based
* auto-detection. Sister dists call archive_register_plugin from BOOT.
*
* Byte sources/sinks: fd, membuf, gzip streaming inflater/deflater.
* The gzip wrappers talk to libz directly; when File::Raw::Gzip 0.02
* exposes its streaming state machine in gz.h these wrappers can be
* simplified to a pull-through.
*/
#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "archive_plugin.h"
#include "arch_io.h"
if (!p) return -1;
s->buf = p;
s->cap = want;
}
memcpy(s->buf + s->len, buf, len);
s->len += len;
return (int)len;
}
/* ============================================================
* gzip streaming source
* ============================================================ */
struct archive_gz_src {
int fd;
z_stream zs;
int zs_inited;
int stream_end;
char *raw;
size_t raw_cap;
int eof;
if (rc == Z_BUF_ERROR && s->eof && s->zs.avail_in == 0) {
return -1;
}
if (rc != Z_OK && rc != Z_BUF_ERROR) return -1;
}
return (int)(len - s->zs.avail_out);
}
/* ============================================================
* gzip streaming sink
* ============================================================ */
struct archive_gz_sink {
int fd;
z_stream zs;
int zs_inited;
char *out;
size_t out_cap;
};
include/arch_io.h view on Meta::CPAN
typedef struct {
char *buf;
size_t cap;
size_t len;
} archive_membuf_sink_t;
int archive_push_membuf(void *state, const char *buf, size_t len);
void archive_membuf_sink_init(archive_membuf_sink_t *s);
void archive_membuf_sink_free(archive_membuf_sink_t *s);
/* gzip streaming source: wraps an fd through libz inflate. We talk to
* libz directly here (rather than going through File::Raw::Gzip's
* not-yet-public-C streaming API). When that API ships in Gzip 0.02,
* this can be reduced to a thin shim. */
typedef struct archive_gz_src archive_gz_src_t;
archive_gz_src_t *archive_gz_src_new (int fd, size_t chunk_size);
void archive_gz_src_free(archive_gz_src_t *s);
int archive_pull_gz (void *state, char *buf, size_t len);
typedef struct archive_gz_sink archive_gz_sink_t;
archive_gz_sink_t *archive_gz_sink_new (int fd, size_t chunk_size, int level);
int archive_gz_sink_finish(archive_gz_sink_t *s);
void archive_gz_sink_free(archive_gz_sink_t *s);
include/archive_plugin.h view on Meta::CPAN
int type; /* ArchiveEntryType */
const char *link_target;
size_t link_target_len;
int is_sparse;
const ArchiveXattr *xattrs;
size_t xattr_count;
void *priv; /* plugin-private scratch */
} ArchiveEntry;
/* Byte source/sink: the Archive layer wires these to either real fds
* or a streaming codec (e.g. gzip inflater). The plugin sees a uniform
* pull/push interface and never knows the difference. */
/* Returns bytes read, 0 = EOF, -1 = error. */
typedef int (*archive_pull_fn)(void *src_state, char *buf, size_t len);
/* Returns bytes written, -1 = error. */
typedef int (*archive_push_fn)(void *sink_state, const char *buf, size_t len);
typedef struct ArchivePlugin ArchivePlugin;
lib/File/Raw/Archive.pm view on Meta::CPAN
# build a tarball
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/'); # dir
$w->add(name => 'src/main.c', content => $main_c);
$w->close;
=head1 DESCRIPTION
C<File::Raw::Archive> handles archive containers with a streaming,
plugin-driven API. The built-in C<tar> plugin reads ustar (POSIX
1988), GNU C<././@LongLink>, and PAX extended-header tarballs, and
writes ustar / GNU / PAX / auto depending on the C<format> option.
Additional format plugins (zip, cpio, ar) can be loaded at run time
by installing the matching C<File::Raw::Archive::*> sister module.
=head1 METHODS
=head2 Reading
( run in 0.621 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )