lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Sun, Dec 18, 2011 at 22:44, Jeremy Jurksztowicz
<> 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.