I'm using Transfer-Encoding: chunked
to write an HTTP response.
The response is split into pieces via the following:
my $template = "a$buffer_size" x int(length($response)/$buffer_size) . 'a*';
foreach my $buffer (unpack $template, $response){
...
}
This works fine when the content type is text/html
, but it is corrupting binary data, such as application/pdf
.
Can unpack
be used to split binary data into equal lengths?
Still not sure why
unpack
is failing in this context, but I stumbled upon a solution.If I manipulate the response with an in-memory file,
unpack
works correctly:Any insight into why this works?