Reusing ltn12 filter from luasocket

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Reusing ltn12 filter from luasocket

aryajur
Hi,
      I was trying to use the ltn12 base64 encoding filter but I think I don't understand it clearly. If I do the following:

Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> mime = require("mime")
> print(ltn12)
table: 00B6D1F0
> enc = mime.encode("base64")
> print(enc("Test Text"))
VGVzdCBUZXh0
> print(enc())
nil
> print(enc())
nil
> print(enc("Test Text"))
nil
>


For the last one I was expecting to give me the encoding again. Why did it give me nil? Is it not the right way to reuse the filter? Any help would be appreciated.

Thanks,
Milind
Reply | Threaded
Open this post in threaded view
|

Re: Reusing ltn12 filter from luasocket

Rena
On Wed, Aug 27, 2014 at 3:55 PM, Milind Gupta <[hidden email]> wrote:

> Hi,
>       I was trying to use the ltn12 base64 encoding filter but I think I
> don't understand it clearly. If I do the following:
>
> Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
>> mime = require("mime")
>> print(ltn12)
> table: 00B6D1F0
>> enc = mime.encode("base64")
>> print(enc("Test Text"))
> VGVzdCBUZXh0
>> print(enc())
> nil
>> print(enc())
> nil
>> print(enc("Test Text"))
> nil
>>
>
>
> For the last one I was expecting to give me the encoding again. Why did it
> give me nil? Is it not the right way to reuse the filter? Any help would be
> appreciated.
>
> Thanks,
> Milind

The filter operates on a stream. Once you pass in nil (or no value),
that signals that the stream has ended. To pass more data afterward
violates the API. (However, you should keep calling it with nil as the
input again until the output is also nil, as filters can generate
additional data.)

--
Sent from my Game Boy.

Reply | Threaded
Open this post in threaded view
|

Re: Reusing ltn12 filter from luasocket

aryajur
Thanks,
Milind


On Wed, Aug 27, 2014 at 1:03 PM, Rena <[hidden email]> wrote:
On Wed, Aug 27, 2014 at 3:55 PM, Milind Gupta <[hidden email]> wrote:
> Hi,
>       I was trying to use the ltn12 base64 encoding filter but I think I
> don't understand it clearly. If I do the following:
>
> Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
>> mime = require("mime")
>> print(ltn12)
> table: 00B6D1F0
>> enc = mime.encode("base64")
>> print(enc("Test Text"))
> VGVzdCBUZXh0
>> print(enc())
> nil
>> print(enc())
> nil
>> print(enc("Test Text"))
> nil
>>
>
>
> For the last one I was expecting to give me the encoding again. Why did it
> give me nil? Is it not the right way to reuse the filter? Any help would be
> appreciated.
>
> Thanks,
> Milind

The filter operates on a stream. Once you pass in nil (or no value),
that signals that the stream has ended. To pass more data afterward
violates the API. (However, you should keep calling it with nil as the
input again until the output is also nil, as filters can generate
additional data.)

--
Sent from my Game Boy.