42
42
<p>By convention, the name of a zip file should end in "<c>.zip</c>".
43
43
To abide to the convention, you'll need to add "<c>.zip</c>" yourself
45
<p>Zip archives are created with the
46
<seealso marker="#zip_2">zip/2</seealso> or the
45
<p>Zip archives are created with the
46
<seealso marker="#zip_2">zip/2</seealso> or the
47
47
<seealso marker="#zip_2">zip/3</seealso> function. (They are
48
48
also available as <c>create</c>, to resemble the <c>erl_tar</c>
50
<p>To extract files from a zip archive, use the
51
<seealso marker="#unzip_1">unzip/1</seealso> or the
50
<p>To extract files from a zip archive, use the
51
<seealso marker="#unzip_1">unzip/1</seealso> or the
52
52
<seealso marker="#unzip_2">unzip/2</seealso> function. (They are
53
53
also available as <c>extract</c>.)</p>
54
<p>To return a list of the files in a zip archive, use the
54
<p>To fold a function over all files in a zip archive, use the
55
<seealso marker="#foldl_3">foldl_3</seealso>.</p>
56
<p>To return a list of the files in a zip archive, use the
55
57
<seealso marker="#list_dir_1">list_dir/1</seealso> or the
56
58
<seealso marker="#list_dir_2">list_dir/2</seealso> function. (They
57
59
are also available as <c>table</c>.)</p>
213
215
<tag><c>all</c></tag>
214
216
<item><p> means that all files will be compressed (as long
215
as they pass the <c>uncompress</c> condition).</p></item>
217
as they pass the <c>uncompress</c> condition).</p></item>
216
218
<tag><c>[Extension]</c></tag>
217
219
<item><p>means that only files with exactly these extensions
218
will be compressed.</p></item>
220
will be compressed.</p></item>
219
221
<tag><c>{add,[Extension]}</c></tag>
220
222
<item><p>adds these extensions to the list of compress
221
extensions.</p></item>
223
extensions.</p></item>
222
224
<tag><c>{del,[Extension]}</c></tag>
223
225
<item><p>deletes these extensions from the list of compress
224
extensions.</p></item>
226
extensions.</p></item>
227
229
<tag><c>{uncompress, What}</c></tag>
332
<name>foldl(Fun, Acc0, Archive) -> {ok, Acc1} | {error, Reason}</name>
333
<fsummary>Fold a function over all files in a zip archive</fsummary>
335
<v>Fun = fun(FileInArchive, GetInfo, GetBin, AccIn) -> AccOut</v>
336
<v>FileInArchive = filename()</v>
337
<v>GetInfo = fun() -> #file_info{}</v>
338
<v>GetBin = fun() -> binary()</v>
339
<v>Acc0 = Acc1 = AccIn = AccOut = term()</v>
340
<v>Archive = filename() | {filename(), binary()}</v>
343
<p>The <marker id="foldl_3"></marker> <c>foldl/3</c> function
344
calls <c>Fun(FileInArchive, GetInfo, GetBin, AccIn)</c> on
345
successive files in the <c>Archive</c>, starting with <c>AccIn
346
== Acc0</c>. <c>FileInArchive</c> is the name that the file
347
has in the archive. <c>GetInfo</c> is a fun that returns info
348
about the the file. <c>GetBin</c> returns the contents of the
349
file. Both <c>GetInfo</c> and <c>GetBin</c> must be called
350
within the <c>Fun</c>. Their behavior is undefined if they are
351
called outside the context of the <c>Fun</c>. The <c>Fun</c>
352
must return a new accumulator which is passed to the next
353
call. <c>foldl/3</c> returns the final value of the
354
accumulator. <c>Acc0</c> is returned if the archive is
355
empty. It is not necessary to iterate over all files in the
356
archive. The iteration may be ended prematurely in a
357
controlled manner by throwing an exception.</p>
361
> <input>Name = "dummy.zip".</input>
363
> <input>{ok, {Name, Bin}} = zip:create(Name, [{"foo", <<"FOO">>}, {"bar", <<"BAR">>}], [memory]).</input>
365
<<80,75,3,4,20,0,0,0,0,0,74,152,97,60,171,39,212,26,3,0,
366
0,0,3,0,0,...>>}}
367
> <input>{ok, FileSpec} = zip:foldl(fun(N, I, B, Acc) -> [{N, B(), I()} | Acc] end, [], {Name, Bin}).</input>
368
{ok,[{"bar",<<"BAR">>,
369
{file_info,3,regular,read_write,
370
{{2010,3,1},{19,2,10}},
371
{{2010,3,1},{19,2,10}},
372
{{2010,3,1},{19,2,10}},
374
{"foo",<<"FOO">>,
375
{file_info,3,regular,read_write,
376
{{2010,3,1},{19,2,10}},
377
{{2010,3,1},{19,2,10}},
378
{{2010,3,1},{19,2,10}},
380
> <input>{ok, {Name, Bin}} = zip:create(Name, lists:reverse(FileSpec), [memory]).</input>
382
<<80,75,3,4,20,0,0,0,0,0,74,152,97,60,171,39,212,26,3,0,
383
0,0,3,0,0,...>>}}
384
> <input>catch zip:foldl(fun("foo", _, B, _) -> throw(B()); (_, _, _, Acc) -> Acc end, [], {Name, Bin}). </input>
385
<<"FOO">>
330
390
<name>list_dir(Archive) -> RetValue</name>
331
391
<name>list_dir(Archive, Options)</name>
332
392
<name>table(Archive) -> RetValue</name>