Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: File extraction 2nd try

by tangent (Parson)
on Jan 19, 2016 at 03:33 UTC ( [id://1153052]=note: print w/replies, xml ) Need Help??


in reply to File extraction 2nd try

What am I doing wrong?
while (my $zeichen = getc($handle1))
This will fail if the character you are reading is "0" or some other "false" value.

Try:

while (defined ( my $zeichen = getc($handle1) ) )
Also, although 'IEND' does signify the end marker of the PNG file it does so as part of a "chunk", and a chunk always ends with a CRC - from the PNG specs:
CRC
A 4-byte CRC (Cyclic Redundancy Check) calculated on the preceding bytes in the chunk, including the chunk type code and chunk data fields, but not including the length field. The CRC is always present, even for chunks containing no data.
So you will need to read/write a further 4 bytes after 'IEND'. I'm no expert on PNG files and can't say this is the correct way to do it but adding these two lines worked for me:
if ($buffer =~ /IEND/) { print $handle2 $buffer; read($handle1, $buffer, $bytes); ### 1 print $handle2 $buffer; ### 2 exit; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1153052]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 23:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found