problem about unpack-Record and share programming errors


  • Trav McKinney
    ruby-on-rails base64 activesupport unpack
    In one of my Rails controllers I am trying to take a Base64 encoded string, decode it and write it to a file (.png). Here is my code:def create_character@character = Character.new(params[:char

  • Bas Jansen
    php arrays decode unpack uncompress
    I have a binary data string that i uncompress and unpack into an array using php with the following code (complete code for this php page is included at the bottom of this question):while ($row = mysql_fetch_array($result, MYSQL_NUM)) {$glycopeptide[$hits] = $row[1];echo $row[4];// $row[4] contains the binaryString$mz = base64_decode($row[4]);$unc_mz = gzuncompress($mz);$max = strlen($unc_mz);$counter = 0;for ($i = 0; $i < $max; $i = $i+4) {$temp = substr($unc_mz,$i,4);$temp = unpack(“f”,$temp);$mz_array[$counter] = $temp[1];$counter++;}$hits++; }I find that both the mz_array (the above code, X-coords) has 9 undefined values (all at the end) but that the int_array (similar code, Y-coords) also has 9 undefined values (distributed throughout the whole array (not grouped or at the beginning/end).Here is an example of a small testing chunk that I added to my page:Test code:for ($i = 0; $i < $counter; $i++) {echo $i;echo ” – “;echo $mz_array[$i];echo ” – “;echo $int_array[$i];echo “
    “; } A “selection” of the output (Note the missing values):671 – 274.20001220703 – 429 672 – 274.39999389648 – 673 – 274.60000610352 – 1098 — skipping a few lines — 10299 – 2199.8000488281 – 0 10300 – 2200 – 0 10301 – – 0 10302 – – 0The weirdest part is that if i manually enter the strings in the complete/original code (see bottom of page) I get the undefined values while if I manually enter the string that is returned by doing “echo $row[4]” (contains the binaryString) in the following code it yields no undefined values. Does anyone have any suggestions or idea’s why this might occur?PS: Can someone add the tag gzuncompress? (I don’t have the reputation for it).EDIT 1I have included an example binaryString (WARNING: Huge!)Y-Coords (retrieved by the commented echo $row[4] in the code):eJztXQuQFMUZblQEQfEQUQSJYwRBSuLG+AAFHdmeRYOPS2lRgEgNvgpLhUuQkooYB5GXBLIaHwRQRwMpCqOuiciJhU4KjUoMnm98r2KUaKkXreBpSCXf3z3Lzu7Na3fn9nZhvqop2N2enu6///7fPcdYjBgxYsSIESNGjBhVgvFGkqmLOWPjk77tlNs5a35AY9kdnBlPo+3GMZ5tm87VmDULfXL/PnOwzkGfP0P7RLj2MUrAaNB0l2OtJuDzVu+188XJnKmnYZ0a5DpZE7Fu3TVm/BOft5TZZ4yqwvwf1u+ne89ea7wM/Pke5vvI3jHfGGVA56xxEnTWKeCT/h588i5k3cEp1vyuxtQN+H/an5+ya9GuBf2t6zi+s2ZAHh/KC+V7BTDXoK/15Y03uxD3zo1urmoKND4efXb17tPqgTZz0OYy/+eaB2uMHYP1UKOjVc1gDuy30TUuz3fWP82NJuy1nZyZx4GXDgO9M/acXgPd9w+mvXFrx66P+TLGNBnXBbXBB4tWwldYhvFcGmI8GbRJ1xGPhFjvPQXqvljDbZjv6jpan1pHfxcfjHyqm0Hra8vnraa+sGF68prmz4aeGtM3Y4wr3fd8I35nrxfZTU/g88YK/NbORAJ6owvG31Y49mwT/JJFXPrjYQBZSrGaAj97UMTrfFYJ4wkD9GUYtcuLBHU7Z/rzoO3dtT1OgQ0Y42neNqyFuSjrOcuamNMo7KPzecHvR45MsYtwKZfAFh7GBS9lv0LbH+BzH+67v7KvcBEDdNrarV0hb77Ddy9VWT9AFmRfwJqtqR+9pF8MGq/iwl7PId1bY62DQcMGB+0hF5W1th8WIO/a7a0TsN+maDK+M9qdnynWao3H76fVAb87oN8K2/s3XNDKfE5jzc0aW7sRNuYhkKM7bFpNt23g/XhhfBp6RtDKoW/UXmjzkaPNefg8j2Jj9UWXmgN4z7gnT0N1IuTRZ5yle4

Originally posted 2013-08-31 04:41:18.