A
alexander
hi there,
last time i accidentely posted this question as a reply to another one..
i´m really sorry for that. i will not make that mistake again.
so here´s my question again in a fresh new thread
i´m having a small problem with base64 decoding a string.
i´m porting a php script over to ruby and the decoding gives me
different results in ruby and in php. the problem is that the php
results works for the processing i do afterwards while the ruby version
doesn´t.
here´s the scripts in question:
php:
<?
$bytes = file_get_contents("test.rgb");
$bitmap = base64_decode($bytes);
$header = "";
$header .= "\xFF\xFE";
$header .= pack("n2",120,97);
$header .= "\x01";
$header .= "\xFF\xFF\xFF\xFF";
$header .= $bitmap;
file_put_contents("test_php.gd",$header);
?>
ruby:
require 'rubygems'
require 'fileutils'
require 'base64'
all_bytes = Base64.decode64(IO.read("test.rgb"))
bitmap = "\xFF\xFE"
bitmap << [120,97].pack("n2")
bitmap << "\x01"
bitmap << "\xFF\xFF\xFF\xFF"
bitmap << all_bytes
File.new("test_ruby.gd","w").puts(bitmap)
the ruby version is one byte shorter.
i´m probably missing something rather obvious here, but any pointers to
how i can make the ruby output be like the php output would be greatly
appreciated
i´ve uploaded the test.rgb file i´m using to here:
http://rss.fork.de/test.rgb if that´s even needed
thanks a lot,
alexander
last time i accidentely posted this question as a reply to another one..
i´m really sorry for that. i will not make that mistake again.
so here´s my question again in a fresh new thread
i´m having a small problem with base64 decoding a string.
i´m porting a php script over to ruby and the decoding gives me
different results in ruby and in php. the problem is that the php
results works for the processing i do afterwards while the ruby version
doesn´t.
here´s the scripts in question:
php:
<?
$bytes = file_get_contents("test.rgb");
$bitmap = base64_decode($bytes);
$header = "";
$header .= "\xFF\xFE";
$header .= pack("n2",120,97);
$header .= "\x01";
$header .= "\xFF\xFF\xFF\xFF";
$header .= $bitmap;
file_put_contents("test_php.gd",$header);
?>
ruby:
require 'rubygems'
require 'fileutils'
require 'base64'
all_bytes = Base64.decode64(IO.read("test.rgb"))
bitmap = "\xFF\xFE"
bitmap << [120,97].pack("n2")
bitmap << "\x01"
bitmap << "\xFF\xFF\xFF\xFF"
bitmap << all_bytes
File.new("test_ruby.gd","w").puts(bitmap)
the ruby version is one byte shorter.
i´m probably missing something rather obvious here, but any pointers to
how i can make the ruby output be like the php output would be greatly
appreciated
i´ve uploaded the test.rgb file i´m using to here:
http://rss.fork.de/test.rgb if that´s even needed
thanks a lot,
alexander