[Klone-users] Download files

thomas fossati tho at koanlogic.com
Tue Jul 28 22:52:29 EDT 2009


Hi Moises,

On Jul 28, 2009, at 7:54 PM, moises acuna wrote:
> Hello all,
> my problem is this, my embedded web application generates binary  
> files and the user is capable to download them. I'm doing it like  
> this:
> [SNIP]
> Expecting for comments and thanks in advanced.

the following POC kl1 hopefully does what you need:

<%!
     #include <u/libu.h>

     #define TEST_FN "/tmp/test"
%><%
     size_t rb;
     char buf[1024];
     FILE *target = NULL;

     target = fopen(TEST_FN, "r");
     warn_err_sifm (target == NULL, "%s", TEST_FN);

     while ((rb = fread(buf, 1, sizeof buf, target)) != 0)
         (void) io_write(out, buf, rb);

     warn_if (!feof(target) && ferror(target));

     // fall through
err:
     if (target)
         fclose(target);
     return;
%>

ciao, t.

PS: the '0xA 0xD' stuff gets in because you probably don't stick '%>< 
%' together: the  kl1 parser interprets the new line literally which  
is clearly not what you want when pushing raw files.

PS2: try to avoid "read" as a variable name as it's already taken by  
the syscall.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://koanlogic.com/pipermail/klone-users/attachments/20090729/894ba1a5/attachment.html


More information about the klone-users mailing list