1
1
defmodule Zstream do
2
2
@ moduledoc """
3
- Module for reading and writing ZIP file stream
4
-
5
- ## Example
6
-
7
- ```
8
- Zstream.zip([
9
- Zstream.entry("report.csv", Stream.map(records, &CSV.dump/1)),
10
- Zstream.entry("catfilm.mp4", File.stream!("/catfilm.mp4", [], 512), coder: Zstream.Coder.Stored)
11
- ])
12
- |> Stream.into(File.stream!("/archive.zip"))
13
- |> Stream.run
14
- ```
15
-
16
- ```
17
- File.stream!("archive.zip", [], 512)
18
- |> Zstream.unzip()
19
- |> Enum.reduce(%{}, fn
20
- {:entry, %Zstream.Entry{name: file_name} = entry}, state -> state
21
- {:data, data}, state -> state
22
- {:data, :eof}, state -> state
23
- end)
24
- ```
3
+ Module for reading and writing ZIP file stream.
25
4
"""
26
5
27
6
defmodule Entry do
@@ -38,58 +17,58 @@ defmodule Zstream do
38
17
@ opaque entry :: map
39
18
40
19
@ doc """
41
- Creates a ZIP file entry with the given `name`
20
+ Creates a ZIP file entry with the given `name`.
42
21
43
22
The `enum` could be either lazy `Stream` or `List`. The elements in `enum`
44
23
should be of type `iodata`
45
24
46
25
## Options
47
26
48
- * `:coder` (module | {module, list}) - The compressor that should be
49
- used to encode the data. Available options are
27
+ * `:coder` (module | {module, list}) - The compressor that should be
28
+ used to encode the data. Available options are:
50
29
51
- `Zstream.Coder.Deflate` - use deflate compression
30
+ - `Zstream.Coder.Deflate` - use deflate compression
52
31
53
- `Zstream.Coder.Stored` - store without any compression
32
+ - `Zstream.Coder.Stored` - store without any compression
54
33
55
- Defaults to `Zstream.Coder.Deflate`
34
+ - Defaults to `Zstream.Coder.Deflate`
56
35
57
- * `:encryption_coder` ({module, keyword}) - The encryption module that should be
58
- used to encrypt the data. Available options are
36
+ * `:encryption_coder` ({module, keyword}) - The encryption module that should be
37
+ used to encrypt the data. Available options are:
59
38
60
- `Zstream.EncryptionCoder.Traditional` - use tranditional zip
61
- encryption scheme. `:password` key should be present in the
62
- options. Example `{Zstream.EncryptionCoder.Traditional, password:
63
- "secret"}`
39
+ - `Zstream.EncryptionCoder.Traditional` - use tranditional zip
40
+ encryption scheme. `:password` key should be present in the
41
+ options. Example `{Zstream.EncryptionCoder.Traditional, password:
42
+ "secret"}`
64
43
65
- `Zstream.EncryptionCoder.None` - no encryption
44
+ - `Zstream.EncryptionCoder.None` - no encryption
66
45
67
- Defaults to `Zstream.EncryptionCoder.None`
46
+ - Defaults to `Zstream.EncryptionCoder.None`
68
47
69
48
70
- * `:mtime` (DateTime) - File last modication time. Defaults to system local time.
49
+ * `:mtime` (DateTime) - File last modication time. Defaults to system local time.
71
50
"""
72
51
@ spec entry ( String . t ( ) , Enumerable . t ( ) , Keyword . t ( ) ) :: entry
73
52
defdelegate entry ( name , enum , options \\ [ ] ) , to: Zstream.Zip
74
53
75
54
@ doc """
76
- Creates a ZIP file stream
55
+ Creates a ZIP file stream.
77
56
78
- entries are consumed one by one in the given order
57
+ Entries are consumed one by one in the given order.
79
58
80
59
## Options
81
60
82
- * `:zip64` (boolean) - If set to `true` zip64 format is used. Zip64
83
- can support files more than 4 GB in size, but not all the unzip
84
- programs support this format. Defaults to `false`
61
+ * `:zip64` (boolean) - If set to `true` zip64 format is used. Zip64
62
+ can support files more than 4 GB in size, but not all the unzip
63
+ programs support this format. Defaults to `false`.
85
64
"""
86
65
@ spec zip ( [ entry ] , Keyword . t ( ) ) :: Enumerable . t ( )
87
66
defdelegate zip ( entries , options \\ [ ] ) , to: Zstream.Zip
88
67
89
68
@ doc """
90
- Unzips file stream
69
+ Unzips file stream.
91
70
92
- returns a new stream which emits the following tuples for each zip entry
71
+ Returns a new stream which emits the following tuples for each zip entry.
93
72
94
73
{`:entry`, `t:Zstream.Entry.t/0`} - Indicates a new file entry.
95
74
@@ -102,11 +81,11 @@ defmodule Zstream do
102
81
allows the writer to zip streams with unknown size. But this
103
82
prevents the reader from unzipping the file in a streaming fashion,
104
83
because to find the file size one has to go to the end of the
105
- stream. Ironcially , if you use Zstream to zip a file, the same file
84
+ stream. Ironically , if you use Zstream to zip a file, the same file
106
85
can't be unzipped using Zstream.
107
86
108
- * doesn 't support file which uses data descriptor header
109
- * doesn 't support encrypted file
87
+ * Doesn 't support file which uses data descriptor header.
88
+ * Doesn 't support encrypted file.
110
89
"""
111
90
defdelegate unzip ( stream ) , to: Zstream.Unzip
112
91
end
0 commit comments