Skip to content

Commit ddfa860

Browse files
authored
add an example of stream composition (#9)
1 parent 75ec995 commit ddfa860

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/src/examples.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,28 @@ makestream("data.txt.bz2")
110110
makestream("data.txt")
111111
```
112112

113+
Change the codec of a file
114+
--------------------------
115+
116+
`TranscodingStream`s are composable: a stream can be an input/output of another
117+
stream. You can use this to chage the codec of a file by composing different
118+
codecs as below:
119+
```julia
120+
using CodecZlib
121+
using CodecZstd
122+
123+
input = open("data.txt.gz", "r")
124+
output = open("data.txt.zst", "w")
125+
126+
stream = GzipDecompressionStream(ZstdCompressionStream(output))
127+
write(stream, input)
128+
close(stream)
129+
```
130+
131+
Effectively, this is equivalent to the following pipeline:
132+
133+
cat data.txt.gz | gzip -d | zstd >data.txt.zst
134+
113135
Transcode data in one shot
114136
--------------------------
115137

0 commit comments

Comments
 (0)