diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-03-16 06:42:53 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-03-16 06:42:53 +0000 |
commit | bcc0c2a9f0be2ca796ef5206a78e283fe15e6186 (patch) | |
tree | 65c269d4854aa5ff4a0b2c8eede5cdb18d716033 /test/mimetest.lua | |
parent | b6edaac2841137cf0ef5105f75358bbab4570d87 (diff) | |
download | luasocket-bcc0c2a9f0be2ca796ef5206a78e283fe15e6186.tar.gz luasocket-bcc0c2a9f0be2ca796ef5206a78e283fe15e6186.tar.bz2 luasocket-bcc0c2a9f0be2ca796ef5206a78e283fe15e6186.zip |
New filter scheme.
ltn12 and mime updated.
smtp/ftp broken.
Diffstat (limited to 'test/mimetest.lua')
-rw-r--r-- | test/mimetest.lua | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/test/mimetest.lua b/test/mimetest.lua index 1a7e427..4a0a20a 100644 --- a/test/mimetest.lua +++ b/test/mimetest.lua | |||
@@ -31,18 +31,27 @@ local mao = [[ | |||
31 | assim, nem tudo o que dava exprimia grande confiança. | 31 | assim, nem tudo o que dava exprimia grande confiança. |
32 | ]] | 32 | ]] |
33 | 33 | ||
34 | local function random(handle, io_err) | ||
35 | if handle then | ||
36 | return function() | ||
37 | local chunk = handle:read(math.random(0, 1024)) | ||
38 | if not chunk then handle:close() end | ||
39 | return chunk | ||
40 | end | ||
41 | else source.empty(io_err or "unable to open file") end | ||
42 | end | ||
43 | |||
44 | local what = nil | ||
34 | local function transform(input, output, filter) | 45 | local function transform(input, output, filter) |
35 | local fi, err = io.open(input, "rb") | 46 | local source = random(io.open(input, "rb")) |
36 | if not fi then fail(err) end | 47 | local sink = ltn12.sink.file(io.open(output, "wb")) |
37 | local fo, err = io.open(output, "wb") | 48 | if what then |
38 | if not fo then fail(err) end | 49 | sink = ltn12.sink.chain(filter, sink) |
39 | while 1 do | 50 | else |
40 | local chunk = fi:read(math.random(0, 1024)) | 51 | source = ltn12.source.chain(source, filter) |
41 | fo:write(filter(chunk)) | 52 | end |
42 | if not chunk then break end | 53 | --what = not what |
43 | end | 54 | ltn12.pump(source, sink) |
44 | fi:close() | ||
45 | fo:close() | ||
46 | end | 55 | end |
47 | 56 | ||
48 | local function encode_qptest(mode) | 57 | local function encode_qptest(mode) |