@@ -7,7 +7,7 @@ TranscodingStreams.jl - IO streams with transcoding
7
7
[ ![ codecov.io] [ codecov-img ]] [ codecov-url ]
8
8
9
9
TranscodingStreams.jl exports a type ` TranscodingStream{C<:Codec,S<:IO}<:IO `
10
- which wraps ` S<:IO ` using ` C<:Codec ` . Codecs are exported from other packages
10
+ which wraps ` S<:IO ` using ` C<:Codec ` . Codecs are defined in other packages
11
11
listed below:
12
12
13
13
- [ CodecZlib.jl] ( https://github.com/bicycle1885/CodecZlib.jl )
@@ -24,10 +24,10 @@ listed below:
24
24
- ` Bzip2Compression ` (` Bzip2CompressionStream ` )
25
25
- ` Bzip2Decompression ` (` Bzip2DecompressionStream ` )
26
26
27
- The following snippet is an example of using CodecZlib.jl, which exports
28
- ` GzipDecompressionStream ` as an alias of
27
+ By convention, codec types have names that match ` .*(De)?Compression ` and I/O
28
+ types have names with ` Stream ` suffix. The following snippet is an example of
29
+ using CodecZlib.jl, which exports ` GzipDecompressionStream ` as an alias of
29
30
` TranscodingStream{GzipDecompression,S} ` where ` S<:IO ` :
30
-
31
31
``` julia
32
32
# Read lines from a gzip-compressed file.
33
33
using CodecZlib
@@ -36,17 +36,34 @@ for line in eachline(stream)
36
36
# do something...
37
37
end
38
38
close (stream)
39
+ ```
39
40
41
+ When writing data, the end of a data stream is indicated by calling ` close ` ,
42
+ which may write an epilogue if necessary and flush all buffered data to the
43
+ underlying I/O stream. If you want to explicitly specify the end position of a
44
+ stream for some reason, you can write ` TranscodingStreams.TOKEN_END ` to the
45
+ transcoding stream as follows:
46
+ ``` julia
40
47
# Compress a string using zstd.
41
48
using CodecZstd
42
49
using TranscodingStreams
43
50
buf = IOBuffer ()
44
51
stream = ZstdCompressionStream (buf)
45
52
write (stream, " foobarbaz" ^ 100 , TranscodingStreams. TOKEN_END)
53
+ flush (stream)
46
54
compressed = take! (buf)
47
55
close (stream)
48
56
```
49
57
58
+ TranscodingStreams.jl extends the ` transcode ` function to transcode a data
59
+ in one shot. ` transcode ` takes a codec object as its first argument and a data
60
+ vector as its second argument:
61
+ ``` julia
62
+ using CodecZlib
63
+ decompressed = transcode (ZlibDecompression (), b " x\x 9cKL*JLNLI\x 04R\x 00\x 19\x f2\x 04U" )
64
+ String (decompressed)
65
+ ```
66
+
50
67
[ travisci-img ] : https://travis-ci.org/bicycle1885/TranscodingStreams.jl.svg?branch=master
51
68
[ travisci-url ] : https://travis-ci.org/bicycle1885/TranscodingStreams.jl
52
69
[ codecov-img ] : http://codecov.io/github/bicycle1885/TranscodingStreams.jl/coverage.svg?branch=master
0 commit comments