Re: lua-l Digest, Vol 17, Issue 45

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

Re: lua-l Digest, Vol 17, Issue 45

Jeremy Jurksztowicz
Please pardon me if this is a FAQ, but my Google-fu is not up to the task.

I'd like to direct io operations to a string buffer rather than a file. My goal is to write a large string, use zlib to compress it, append a header and then write it to a file. I'd obviously like to keep everything in memory until the last step. I can write a C module to handle this, or just use standard lua strings, but this seems like it'd be a frequently needed item, so I'm checking to see if there is a common implementation.

Thanks for your attention.
Reply | Threaded
Open this post in threaded view
|

Re: lua-l Digest, Vol 17, Issue 45

Rena
On Sun, Dec 18, 2011 at 22:44, Jeremy Jurksztowicz
<[hidden email]> wrote:

> Please pardon me if this is a FAQ, but my Google-fu is not up to the task.
>
> I'd like to direct io operations to a string buffer rather than a file. My
> goal is to write a large string, use zlib to compress it, append a header
> and then write it to a file. I'd obviously like to keep everything in memory
> until the last step. I can write a C module to handle this, or just use
> standard lua strings, but this seems like it'd be a frequently needed item,
> so I'm checking to see if there is a common implementation.
>
> Thanks for your attention.

I'm not sure what you're asking. How to redirect file operations? Just
create your own object/table containing the methods a file would have
(read, write, seek, etc) that performs them on a string. I would
recommend using a mutable buffer in C instead of Lua strings for this
if you're writing a lot.

Alternatively, just use a temporary file.

--
Sent from my toaster.