modules/base: ltn12: source.file() should terminate when an empty chunk is read 257/head
authorMatthias Schiffer <mschiffer@universe-factory.net>
Mon, 17 Nov 2014 13:25:51 +0000 (14:25 +0100)
committerMatthias Schiffer <mschiffer@universe-factory.net>
Mon, 17 Nov 2014 13:35:24 +0000 (14:35 +0100)
The read method of nixio's file and socket objects both return an empty string
when they reach EOF, not nil, causing the consumer to loop endlessly as
source.file() never terminates.

As there is no other situation in which an empty chunk is read, just change it
to nil to terminate the consumer's loop.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
modules/base/luasrc/ltn12.lua

index 9371290..b59fb8c 100644 (file)
@@ -144,6 +144,7 @@ function source.file(handle, io_err)
     if handle then
         return function()
             local chunk = handle:read(BLOCKSIZE)
+            if chunk and chunk:len() == 0 then chunk = nil end
             if not chunk then handle:close() end
             return chunk
         end