@@ -51,26 +51,46 @@ The following snippet is an example of using CodecZlib.jl, which exports
51
51
` TranscodingStream{GzipDecompression,S} where S<:IO ` :
52
52
``` julia
53
53
using CodecZlib
54
- stream = GzipDecompressionStream (open (" data.gzip " ))
54
+ stream = GzipDecompressionStream (open (" data.txt.gz " ))
55
55
for line in eachline (stream)
56
56
# do something...
57
57
end
58
58
close (stream)
59
59
```
60
60
61
+ Note that the last ` close ` call will close the file as well. Alternatively,
62
+ ` open(<stream type>, <filepath>) do ... end ` syntax will close the file at the
63
+ end:
64
+ ``` julia
65
+ using CodecZlib
66
+ open (GzipDecompressionStream, " data.txt.gz" ) do stream
67
+ for line in eachline (stream)
68
+ # do something...
69
+ end
70
+ end
71
+ ```
72
+
61
73
### Save a data matrix with Zstd compression
62
74
63
75
Writing compressed data is easy. One thing you need to keep in mind is to call
64
76
` close ` after writing data; otherwise, the output file will be incomplete:
65
77
``` julia
66
78
using CodecZstd
67
- mat = randn (100 , 100 ).^ 2
68
- file = open (" data.mat.zst" , " w" )
69
- stream = ZstdCompressionStream (file)
79
+ mat = randn (100 , 100 )
80
+ stream = ZstdCompressionStream (open (" data.mat.zst" , " w" ))
70
81
writedlm (stream, mat)
71
82
close (stream)
72
83
```
73
84
85
+ Of course, ` open(<stream type>, ...) do ... end ` works well:
86
+ ``` julia
87
+ using CodecZstd
88
+ mat = randn (100 , 100 )
89
+ open (ZstdCompressionStream, " data.mat.zst" , " w" ) do stream
90
+ writedlm (stream, mat)
91
+ end
92
+ ```
93
+
74
94
### Explicitly finish transcoding by writing ` TOKEN_END `
75
95
76
96
When writing data, the end of a data stream is indicated by calling ` close ` ,
0 commit comments