Preklopeni binarniho souboru do TXT

Tom Meinlschmidt hw na meinlschmidt.org
Pátek Leden 27 17:12:34 CET 2017


mno :) jen vzdycky je lepsi, pokud to jsou binarni data, pouzivat u 
fread/fwrite priznak 'b', tzn.
fopen($soubor2, "rb") i u write fopen(.. , "wb")

tm


On 2017-01-27 15:26, hwnews konference wrote:
> no ja jsem to take nevydrzel...a napsal si to po svojem:
> 
> <?php
> 
> $soubor1=$_GET["soubor"];
> $soubor2="./data/".$soubor1;
> echo $soubor2;
> $poc=0;
> $byteArray=array();
> 
> $fsize = filesize($soubor2);
> echo ".....velikost: ".$fsize;
> echo "<br>";
> 
> $handle = fopen($soubor2, "r");
> while (!feof($handle)) {
>         $pom = fread($handle,1);
>         $poc++;
>         $byteArray[$poc] = $pom;
>         //echo $byteArray[$poc];
> }
> fclose($handle);
> 
> $poc--;
> $poc2=0;
> $handle = fopen("./data/".$soubor1.".txt", "w");
> while ($poc>0) {
>     $fwrite = fwrite($handle, ord($byteArray[$poc]));
>     $fwrite = fwrite($handle, ',');
>     if ($poc2==31) {
>        $fwrite = fwrite($handle,"\r\n");
>        $poc2=0;
>     }
>     $poc2++;
>     $poc--;
> }
> fclose($handle);
> 
> ?>
> 
> Dne 27. ledna 2017 10:51 Jindroush <jindroush na seznam.cz> napsal(a):
> 
>> Pravda. Vtip je v tom, ze ten soubor se nacte po 'radkach', nikoli
>> jako jeden binarni blob, takze pak se to reverse dela v ramci
>> radku...
>> 
>> Nevim, jak to v tom onelineru fixnout.
>> J.
>> 
>> On 27.1.2017 10:08, Tom Meinlschmidt wrote:
>> zkuste sam..
>> 
>> dd if=/dev/random of=file.txt bs=1024 count=64
>> cat file.txt | perl -⁠ne "print
>> join(',',reverse(unpack('C*',$_)));"
>> 
>> a ted pro porovnani
>> hexdump file.txt | head -1
>> 
>> ja dostanu z perlu:
>> 
> ...,246,84,216,25,165,38,166,71,37,97,194,240,197,50,33,213,201,79,242,13,74,191,255,208,145(EOF)
>> 
>> a z hexdumpu
>> 0000000 8c 58 a8 b2 55 dd c6 02 7b 59 79 ea 01 ba 98 9d
>> 
>> resp
>> hexdump -v -e '16/1 "%03u " "\n"' file.txt |head -1
>> 140 088 168 178 085 221 198 002 123 089 121 234 001 186 152 157
>> 
>> coz proste nesedi s tim perlem. Perl by mel koncit na 088 140...
>> 
>> tm
>> 
>> On 2017-01-27 08:30, Jindroush wrote:
>> Proc, co je v nem blbe? Proste vezme vstup a vypise ho jako dec
>> cisla
>> oddelena carkou, tak jsem pochopil zadani, na linuxu by nemelo
>> vadit
>> nejaky hrani s binary a tak...
>> 
>> On 27.1.2017 0:23, Tom Meinlschmidt wrote:
>> chyba.
>> 
>> ma byt hexdump -v -e '/1 "%03d" " “‘ … a "od -An -tuC"
>> 
>> jinak to bylo v osmickove..
>> 
>> btw - ten perl taky nefunguje spravne...
>> 
>> tm
>> 
>> On Jan 27, 2017, at 0:02 , Tom Meinlschmidt <hw na meinlschmidt.org>
>> wrote:
>> 
>> test - 64kB soubor (data z /dev/random)
>> 
>> cat file.txt | hexdump -v -e '/1 "%03o" "\n"' | tac | xargs -n8 |
>> tr
>> ' ' ','
>> 
>> real 0m26.837s
>> user 0m7.769s
>> sys 0m11.485s
>> 
>> bez zarovnavani na 8 sloupcu
>> 
>> cat file.txt | hexdump -v -e '/1 "%03o" " "' | tac -s’ ‘ | tr
>> ‘ ‘ ‘,'
>> 
>> real 0m0.333s
>> user 0m0.048s
>> sys 0m0.022s
>> 
>> nebo
>> 
>> cat file.txt | od -An -b | cut -c 2- | tr ' ' '\n' | tac | xargs
>> -n8
>> | tr ' ' ','
>> 
>> real 0m28.978s
>> user 0m8.125s
>> sys 0m12.093s
>> 
>> nebo
>> 
>> cat file.txt | od -An -b | cut -c 2- | tr '\n' ' ' | tac -s ' ' |
>> tr
>> ' ' ‘,'
>> 
>> real 0m0.404s
>> user 0m0.051s
>> sys 0m0.028s
>> 
>> tm
>> 
>> On Jan 26, 2017, at 22:05 , Admin HWnews <hwnews na cncnet.info>
>> wrote:
>> 
>> Hmm prisel jsem na dalsi spek....
>> 
>> Ja bych ten soubor potreboval jeste prevratit...tedy aby posledni
>> bajt byl prvni. Nejakej napad?
>> 
>> Prece to nebudu prohanet pres tabulku v DB...
>> 
>> RV
>> 
>> Dne 24.1.2017 v 17:51 Tom Meinlschmidt napsal(a):
>> odvolavam, co jsem neslibil. mate pravdu - potrebuje to -v
>> tm
>> 
>> On Jan 24, 2017, at 17:37 , Tom Meinlschmidt
>> <hw na meinlschmidt.org> wrote:
>> 
>> ? bash?
>> 
>> $ printf 'e\0\0\0cho a\0\0b\n' | hexdump -v -e '/1 "%03o" "\n"' |
>> xargs -n8 | tr ' ' ','
>> 145,000,000,000,143,150,157,040
>> 141,000,000,142,012
>> 
>> tm
>> 
>> On 2017-01-24 17:24, Petr Simek wrote:
>> On Tue, 24 Jan 2017, Tom Meinlschmidt wrote:
>> co treba
>> hexdump -e '/1 "%03o" "\n"' /bin/bash | xargs -n8 | tr ' ' ','
>> Kdyz jsou v souboru dve nuly za sebou tak to prvni vypise jako
>> 060 a
>> tu druhou jako * .
>> tm
>> 
> *------------------------------------------------------------------------*
>> 
>> | Petr Simek APS
>> JU |
>> |
>> psimek na jcu.cz |
>> 
> *------------------------------------------------------------------------*
>> 
>> _______________________________________________
>> HW-list mailing list - sponsored by www.HW.cz [1]
>> Hw-list na list.hw.cz
>> http://list.hw.cz/mailman/listinfo/hw-list [2]
>  _______________________________________________
>  HW-list mailing list  -  sponsored by www.HW.cz [1]
>  Hw-list na list.hw.cz
>  http://list.hw.cz/mailman/listinfo/hw-list [2]
> 
>  _______________________________________________
>  HW-list mailing list  -  sponsored by www.HW.cz [1]
>  Hw-list na list.hw.cz
>  http://list.hw.cz/mailman/listinfo/hw-list [2]
> 
>  --
>  
> ===============================================================================
> 
>  Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache
> 
>  www.meinlschmidt.com [3]  www.maxwellrender.cz [4]
>  
> ===============================================================================
> 
>  _______________________________________________
>  HW-list mailing list  -  sponsored by www.HW.cz [1]
>  Hw-list na list.hw.cz
>  http://list.hw.cz/mailman/listinfo/hw-list [2]
> 
>  _______________________________________________
>  HW-list mailing list  -  sponsored by www.HW.cz [1]
>  Hw-list na list.hw.cz
>  http://list.hw.cz/mailman/listinfo/hw-list [2]
> 
>  --
>  Jindroush <jindroush na seznam.cz>
> 
>  _______________________________________________
>  HW-list mailing list  -  sponsored by www.HW.cz [1]
>  Hw-list na list.hw.cz
>  http://list.hw.cz/mailman/listinfo/hw-list [2]
> 
> 
> 
> Links:
> ------
> [1] http://www.HW.cz
> [2] http://list.hw.cz/mailman/listinfo/hw-list
> [3] http://www.meinlschmidt.com
> [4] http://www.maxwellrender.cz
> 
> _______________________________________________
> HW-list mailing list  -  sponsored by www.HW.cz
> Hw-list na list.hw.cz
> http://list.hw.cz/mailman/listinfo/hw-list


Další informace o konferenci Hw-list