mIRC Home    About    Download    Register    News    Help

Print Thread
#113553 06/03/05 09:23 AM
Joined: May 2003
Posts: 18
K
kinnu Offline OP
Pikka bird
OP Offline
Pikka bird
K
Joined: May 2003
Posts: 18
It would be great if $encode and $decode could handle URL-encoding (as in application/x-www-form-urlencoded). Yes, it is easy to script, but the speed is just terrible - around 10KB per second on 1.2Ghz AMD. Not good if you are looking to HTTP POST several megabytes of data.

Code:
alias urlencode {
  bread "c:\binary.junk" 1 102400 &bin
  var %start = $ctime, %i = 1, %temp
  while (%i <= 102400) {
    %temp = % $+ $base($bvar(&bin,%i,1),10,16,2)
    inc %i
  }
  echo -s Encoded 100 KB in $calc($ctime - %start) seconds
}


(I know this snippet "over-encodes", A-Z etc don't need to be converted. But adding n+1 tests of the ascii value would only make is slower. Mirc's $encode could and should do proper encoding.)

#113554 06/03/05 11:02 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
The biggest slow down you have is the fact your doing one byte at a time, since i dont have the slightest idea what asc values are allowed and what arent i wrote soemthing to half your time but also does all the bytes values converted, maybe if i had a list of allowables but i didnt frown
PLEASE NOTE THE /BREAD starts from the 1st byte of the file now (zero offset binary reading)

Code:
alias urlencode {
  bread "c:\binary.junk" 0 102400 &bin
  var %start = $ctime, %i = 1, %temp
  while (%i <= 102400) {
    var %t = $replace($+(.,$bvar(&bin,%i,225),.),$chr(32),.,.9.,.09.,.8.,.08.,.7.,.07.,.6.,.06.,.5.,.05.,.4.,.04.,.3.,.03.,.2.,.02.,.1.,.01.,.0.,.00.)
    var %t = $replacex(%t,.,-,255,FF,254,FE,253,FD,252,FC,251,FB,250,FA,249,F9,248,F8,247,F7,246,F6,245,F5,244,F4,243,F3,242,F2,241,F1,240,F0,239,EF,238,EE,237,ED,236,EC,235,EB,234,EA,233,E9,232,E8,231,E7,230,E6,229,E5,228,E4,227,E3,226,E2,225,E1,224,E0,223,DF,222,DE,221,DD,220,DC,219,DB,218,DA,217,D9,216,D8,215,D7,214,D6,213,D5,212,D4,211,D3,210,D2,209,D1,208,D0,207,CF,206,CE,205,CD,204,CC,203,CB,202,CA,201,C9,200,C8,199,C7,198,C6,197,C5,196,C4,195,C3,194,C2,193,C1,192,C0,191,BF,190,BE,189,BD,188,BC,187,BB,186,BA,185,B9,184,B8,183,B7,182,B6,181,B5,180,B4,179,B3,178,B2,177,B1,176,B0,175,AF,174,AE,173,AD,172,AC,171,AB,170,AA,169,A9,168,A8,167,A7,166,A6,165,A5,164,A4,163,A3,162,A2,161,A1,160,A0,159,9F,158,9E,157,9D,156,9C,155,9B,154,9A,143,8F,142,8E,141,8D,140,8C,139,8B,138,8A,127,7F,126,7E,125,7D,124,7C,123,7B,122,7A,111,6F,110,6E,109,6D)
    var %t = $replacex(%t,-,%,108,6C,107,6B,106,6A,95,5F,94,5E,93,5D,92,5C,91,5B,90,5A,79,4F,78,4E,77,4D,76,4C,75,4B,74,4A,63,3F,62,3E,61,3D,60,3C,59,3B,58,3A,47,2F,46,2E,45,2D,44,2C,43,2B,42,2A,31,1F,30,1E,29,1D,28,1C,27,1B,26,1A,153,99,152,98,151,97,150,96,149,95,148,94,147,93,146,92,145,91,144,90,137,89,136,88,135,87,134,86,133,85,132,84,131,83,130,82,129,81,128,80,121,79,120,78,119,77,118,76,117,75,116,74,115,73,114,72,113,71,112,70,105,69,104,68,103,67,102,66,101,65,100,64,99,63,98,62,97,61,96,60,89,59,88,58,87,57,86,56,85,55,84,54,83,53,82,52,81,51,80,50,73,49,72,48,71,47,70,46,69,45,68,44,67,43,66,42,65,41,64,40,57,39,56,38,55,37,54,36,53,35,52,34,51,33,50,32,49,31,48,30,41,29,40,28,39,27,38,26,37,25,36,24,35,23,34,22,33,21,32,20,25,19,24,18,23,17,22,16,21,15,20,14,19,13,18,12,17,11,16,10,15,0F,14,0E,13,0D,12,0C,11,0B,10,0A)
    var %t = $left(%t,-1)
    inc %i 225
  }
  echo -s Encoded 100 KB in $calc($ctime - %start) seconds
}


I was originally gonna have it alot simplier aka var %t = $replacex($+($chr(32),$bvar(&bin,%i,225)),$chr(32),%,255,FF,254,FE,253,FD .... 2,02,1,01,0,00) but i couldnt fit all the replacex's on one line which really complicated it, as the second one must not alter the first one, which is the cause for all the wierd ordering frown of replacements.
225 bytes a time since 4 chars max per byte returned by $bvar = 900 which is closing on max text length.

#113555 07/03/05 10:22 AM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
It's not necessary to encode a file to upload it to an HTTP server.

In this script I tried to imitate the way a browser would upload the file, and it appears to work.


Link Copied to Clipboard