Mailing List Archive

Outputting binary data with NUL char
Is Embperl supposed to suppress the output of NUL characters?

Let's say for example that I want to write an embperl script that outputs a GIF (here's a trivial example for illustration purposes):

[.+
$http_headers_out{'Content-Type'} = 'image/gif';
local $escmode = 0;
`cat test.gif`;
+]

In the example above, there is no whitespace in the .epl file outside the [++].

What happens is that Embperl cuts of the output at the first NUL (ascii-zero) character in the output data.

So in this example, I get just the following characters:

GIF89a\220 (and a spurious return). The content-length header says "9" (but should actually say 8). The remaining characters are suppressed.


So: am I off base for even trying this? I realize that embperl is designed for text-based HTML output, but I have lots of embperl apps, and it's just more convenient for me to do this one app that has to return an image as an embperl app than to set up a registry CGI script to do it.


-c

------------------------------------------------------------------------
Chris Thorman (413) 473-0853 e-fax
------------------------------------------------------------------------
RE: Outputting binary data with NUL char [ In reply to ]
>
> Is Embperl supposed to suppress the output of NUL characters?
>

Embperl 1.x is using NUL terminated C strings internaly, so it's
interpreting a NUL char as end of string. So currently your only chance is
to setup a registry script.

Embperl 2.0 (on which I do currently alpha testing) will not have this
limitation.

Gerald


> Let's say for example that I want to write an embperl script that
> outputs a GIF (here's a trivial example for illustration purposes):
>
> [.+
> $http_headers_out{'Content-Type'} = 'image/gif';
> local $escmode = 0;
> `cat test.gif`;
> +]
>
> In the example above, there is no whitespace in the .epl file
> outside the [++].
>
> What happens is that Embperl cuts of the output at the first NUL
> (ascii-zero) character in the output data.
>
> So in this example, I get just the following characters:
>
> GIF89a\220 (and a spurious return). The content-length header
> says "9" (but should actually say 8). The remaining characters
> are suppressed.
>
>
> So: am I off base for even trying this? I realize that embperl
> is designed for text-based HTML output, but I have lots of
> embperl apps, and it's just more convenient for me to do this one
> app that has to return an image as an embperl app than to set up
> a registry CGI script to do it.
>
>
> -c
>
> ------------------------------------------------------------------------
> Chris Thorman (413) 473-0853 e-fax
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org
>
>