<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="../nih-man.css" type="text/css" media="all"/>
<title>ZIP_SOURCE_LAYERED(3)</title>
</head>
<body>
<table class="head">
<tr>
<td class="head-ltitle">ZIP_SOURCE_LAYERED(3)</td>
<td class="head-vol">Library Functions Manual</td>
<td class="head-rtitle">ZIP_SOURCE_LAYERED(3)</td>
</tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">zip_source_layered</code>,
<code class="Nm">zip_source_layered_create</code> —
<span class="Nd">create layered data source from function</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="LIBRARY"><a class="permalink" href="#LIBRARY">LIBRARY</a></h1>
<p class="Pp">libzip (-lzip)</p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<p class="Pp"><code class="In">#include
<<a class="In">zip.h</a>></code></p>
<p class="Pp"><var class="Ft">zip_source_t *</var>
<br/>
<code class="Fn">zip_source_layered</code>(<var class="Fa" style="white-space: nowrap;">zip_t
*archive</var>, <var class="Fa" style="white-space: nowrap;">zip_source_t
*source</var>,
<var class="Fa" style="white-space: nowrap;">zip_source_layered_callback
fn</var>, <var class="Fa" style="white-space: nowrap;">void
*userdata</var>);</p>
<p class="Pp"><var class="Ft">zip_source_t *</var>
<br/>
<code class="Fn">zip_source_layered_create</code>(<var class="Fa" style="white-space: nowrap;">zip_source_t
*source</var>,
<var class="Fa" style="white-space: nowrap;">zip_source_layered_callback
fn</var>, <var class="Fa" style="white-space: nowrap;">void *userdata</var>,
<var class="Fa" style="white-space: nowrap;">zip_error_t *error</var>);</p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp">The functions
<a class="permalink" href="#zip_source_layered"><code class="Fn" id="zip_source_layered">zip_source_layered</code></a>()
and
<a class="permalink" href="#zip_source_layered_create"><code class="Fn" id="zip_source_layered_create">zip_source_layered_create</code></a>()
create a layered zip source from the user-provided function
<var class="Ar">fn</var>, which must be of the following type:</p>
<p class="Pp"><var class="Ft">typedef zip_int64_t</var>
<code class="Fn">(*p_source_layered_callback)</code>(<var class="Fa">zip_source_t
*source</var>, <var class="Fa">void *userdata</var>, <var class="Fa">void
*data</var>, <var class="Fa">zip_uint64_t length</var>,
<var class="Fa">zip_source_cmd_t cmd</var>);</p>
<p class="Pp"><var class="Ar">archive</var> or <var class="Ar">error</var> are
used for reporting errors and can be <code class="Dv">NULL</code>.</p>
<p class="Pp">When called by the library, the first argument is the
<var class="Ar">source</var> of the lower layer, the second argument is the
<var class="Ar">userdata</var> argument supplied to the function. The next
two arguments are a buffer <var class="Ar">data</var> of size
<var class="Ar">length</var> when data is passed in or expected to be
returned, or else <code class="Dv">NULL</code> and 0. The last argument,
<var class="Ar">cmd</var>, specifies which action the function should
perform.</p>
<p class="Pp">See
<a class="Xr" href="zip_source_function.html">zip_source_function(3)</a> for
a description of the commands.</p>
<p class="Pp">A layered source transforms the data or metadata of the source
below in some way. Layered sources can't support writing and are not
sufficient to cleanly add support for additional compression or encryption
methods. This may be revised in a later release of libzip.</p>
<p class="Pp">On success, the layered source takes ownership of
<var class="Ar">source</var>. The caller should not free it.</p>
<p class="Pp">The interaction with the lower layer depends on the command:</p>
<section class="Ss">
<h2 class="Ss" id="ZIP_SOURCE_ACCEPT_EMPTY"><a class="permalink" href="#ZIP_SOURCE_ACCEPT_EMPTY"><code class="Dv">ZIP_SOURCE_ACCEPT_EMPTY</code></a></h2>
<p class="Pp">If the layered source supports this command, the lower layer is
not called automatically. Otherwise, the return value of the lower source is
used.</p>
</section>
<section class="Ss">
<h2 class="Ss" id="ZIP_SOURCE_CLOSE"><a class="permalink" href="#ZIP_SOURCE_CLOSE"><code class="Dv">ZIP_SOURCE_CLOSE</code></a></h2>
<p class="Pp">The lower layer is closed after the callback returns.</p>
</section>
<section class="Ss">
<h2 class="Ss" id="ZIP_SOURCE_ERROR"><a class="permalink" href="#ZIP_SOURCE_ERROR"><code class="Dv">ZIP_SOURCE_ERROR</code></a></h2>
<p class="Pp">The lower layer is not called automatically. If you need to
retrieve error information from the lower layer, use
<a class="Xr" href="zip_error_set_from_source.html">zip_error_set_from_source(3)</a>
or
<a class="Xr" href="zip_source_pass_to_lower_layer.html">zip_source_pass_to_lower_layer(3)</a>.</p>
</section>
<section class="Ss">
<h2 class="Ss" id="ZIP_SOURCE_FREE"><a class="permalink" href="#ZIP_SOURCE_FREE"><code class="Dv">ZIP_SOURCE_FREE</code></a></h2>
<p class="Pp">The lower layer is freed after the callback returns.</p>
</section>
<section class="Ss">
<h2 class="Ss" id="ZIP_SOURCE_GET_FILE_ATTRIBUTES"><a class="permalink" href="#ZIP_SOURCE_GET_FILE_ATTRIBUTES"><code class="Dv">ZIP_SOURCE_GET_FILE_ATTRIBUTES</code></a></h2>
<p class="Pp">The attributes of the lower layer are merged with the attributes
returned by the callback: information set by the callback wins over the
lower layer, with the following exceptions: the higher
<var class="Ar">version_needed</var> is used, and
<var class="Ar">general_purpose_bit_flags</var> are only overwritten if the
corresponding bit is set in
<var class="Ar">general_purpose_bit_mask</var>.</p>
</section>
<section class="Ss">
<h2 class="Ss" id="ZIP_SOURCE_OPEN"><a class="permalink" href="#ZIP_SOURCE_OPEN"><code class="Dv">ZIP_SOURCE_OPEN</code></a></h2>
<p class="Pp">The lower layer is opened before the callback is called.</p>
</section>
<section class="Ss">
<h2 class="Ss" id="ZIP_SOURCE_READ"><a class="permalink" href="#ZIP_SOURCE_READ"><code class="Dv">ZIP_SOURCE_READ</code></a></h2>
<p class="Pp">The lower layer is not called automatically.</p>
</section>
<section class="Ss">
<h2 class="Ss" id="ZIP_SOURCE_SEEK"><a class="permalink" href="#ZIP_SOURCE_SEEK"><code class="Dv">ZIP_SOURCE_SEEK</code></a></h2>
<p class="Pp">The lower layer is not called automatically.</p>
</section>
<section class="Ss">
<h2 class="Ss" id="ZIP_SOURCE_STAT"><a class="permalink" href="#ZIP_SOURCE_STAT"><code class="Dv">ZIP_SOURCE_STAT</code></a></h2>
<p class="Pp"><var class="Ar">data</var> contains the stat information from the
lower layer when the callback is called.</p>
</section>
<section class="Ss">
<h2 class="Ss" id="ZIP_SOURCE_SUPPORTS"><a class="permalink" href="#ZIP_SOURCE_SUPPORTS"><code class="Dv">ZIP_SOURCE_SUPPORTS</code></a></h2>
<p class="Pp"><var class="Ar">data</var> contains the bitmap of commands
supported by the lower layer when the callback is called. Since layered
sources can't support writing, all commands related to writing are stripped
from the returned support bitmap.</p>
</section>
<section class="Ss">
<h2 class="Ss" id="ZIP_SOURCE_TELL"><a class="permalink" href="#ZIP_SOURCE_TELL"><code class="Dv">ZIP_SOURCE_TELL</code></a></h2>
<p class="Pp">The lower layer is not called automatically.</p>
</section>
</section>
<section class="Sh">
<h1 class="Sh" id="RETURN_VALUES"><a class="permalink" href="#RETURN_VALUES">RETURN
VALUES</a></h1>
<p class="Pp">Upon successful completion, the created source is returned.
Otherwise, <code class="Dv">NULL</code> is returned and the error code in
<var class="Ar">archive</var> or <var class="Ar">error</var> is set to
indicate the error (unless it is <code class="Dv">NULL</code>).</p>
</section>
<section class="Sh">
<h1 class="Sh" id="ERRORS"><a class="permalink" href="#ERRORS">ERRORS</a></h1>
<p class="Pp"><code class="Fn">zip_source_layered</code>() fails if:</p>
<dl class="Bl-tag">
<dt id="ZIP_ER_MEMORY">[<a class="permalink" href="#ZIP_ER_MEMORY"><code class="Er">ZIP_ER_MEMORY</code></a>]</dt>
<dd>Required memory could not be allocated.</dd>
</dl>
</section>
<section class="Sh">
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
ALSO</a></h1>
<p class="Pp"><a class="Xr" href="libzip.html">libzip(3)</a>,
<a class="Xr" href="zip_file_add.html">zip_file_add(3)</a>,
<a class="Xr" href="zip_file_attributes_init.html">zip_file_attributes_init(3)</a>,
<a class="Xr" href="zip_file_replace.html">zip_file_replace(3)</a>,
<a class="Xr" href="zip_source.html">zip_source(5)</a>,
<a class="Xr" href="zip_source_function.html">zip_source_function(3)</a>,
<a class="Xr" href="zip_source_pass_to_lower_layer.html">zip_source_pass_to_lower_layer(3)</a></p>
</section>
<section class="Sh">
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
<p class="Pp"><code class="Fn">zip_source_layered</code>() and
<code class="Fn">zip_source_layered_create</code>() were added in libzip
1.10.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="AUTHORS"><a class="permalink" href="#AUTHORS">AUTHORS</a></h1>
<p class="Pp"><span class="An">Dieter Baron</span>
<<a class="Mt" href="mailto:dillo@nih.at">dillo@nih.at</a>> and
<span class="An">Thomas Klausner</span>
<<a class="Mt" href="mailto:wiz@gatalith.at">wiz@gatalith.at</a>></p>
</section>
</div>
<table class="foot">
<tr>
<td class="foot-date">January 20, 2023</td>
<td class="foot-os">NiH</td>
</tr>
</table>
</body>
</html>