PMbwmon bandwidth monitor: can specify which interfaces to watch, also supporting...
[hband-tools.git] / user-tools / dataurl2bin
blob68a34e2bea1c12c7497b384cbc6371378be8fd33
1 #!/usr/bin/env perl
3 use MIME::Decoder;
6 sub readupto
8 my $stream = shift;
9 my $stopchar = shift;
10 my $c;
11 my $out;
13 while(1)
15 my $ok = read $stream, $c, 1;
16 if(not defined $ok) { die "read error $!\n"; }
17 if(!$ok or $c eq $stopchar) { return $out; }
18 $out .= $c;
22 $scheme = readupto \*STDIN, ':';
23 $scheme eq 'data' or die "stdin is not a data url\n";
25 $meta = readupto \*STDIN, ',';
26 if($meta =~ /([^;]+);(.*)/)
28 ($mime, $encoding) = ($1, $2);
30 else
32 $mime = $meta;
33 $encoding = 'base64';
36 warn "MIME type is '$mime'\n";
38 $decoder = new MIME::Decoder $encoding or die "unsupported encoding '$encoding'\n";
39 $decoder->decode(\*STDIN, \*STDOUT) or die "decode error\n";
42 __END__
44 =pod
46 =head1 NAME
48 dataurl2bin - Decode "data:..." URLs from input stream and output the raw binary data
50 =cut