bmk_bank.bmx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. Strict
  2. Import "bmk_config.bmx"
  3. Import Pub.ZLib
  4. Import BRL.SocketStream
  5. Function CompressBank:TBank( bank:TBank )
  6. ?bmxng And (win32 Or ptr32)
  7. Local size:UInt=bank.Size()
  8. Local out_size:UInt=size+size/10+32
  9. ?bmxng And ptr64 And Not win32
  10. Local size:ULong=bank.Size()
  11. Local out_size:ULong=size+size/10+32
  12. ?bmxng
  13. Local out:TBank=TBank.Create( Size_T(out_size) )
  14. ?Not bmxng
  15. Local size=bank.Size()
  16. Local out_size=size+size/10+32
  17. Local out:TBank=TBank.Create( out_size )
  18. ?
  19. compress out.Buf()+4,out_size,bank.Buf(),size
  20. out.PokeByte 0,Int(size)
  21. out.PokeByte 1,Int(size Shr 8)
  22. out.PokeByte 2,Int(size Shr 16)
  23. out.PokeByte 3,Int(size Shr 24)
  24. ?bmxng
  25. out.Resize Size_T(out_size+4)
  26. ?Not bmxng
  27. out.Resize out_size+4
  28. ?
  29. Return out
  30. End Function
  31. Function UncompressBank:TBank( bank:TBank )
  32. ?bmxng And (win32 Or ptr32)
  33. Local out_size:UInt
  34. ?bmxng And ptr64 And Not win32
  35. Local out_size:ULong
  36. ?Not bmxng
  37. Local out_size
  38. ?
  39. out_size:|bank.PeekByte(0)
  40. out_size:|bank.PeekByte(1) Shl 8
  41. out_size:|bank.PeekByte(2) Shl 16
  42. out_size:|bank.PeekByte(3) Shl 24
  43. ?bmxng
  44. Local out:TBank=TBank.Create( Size_T(out_size) )
  45. uncompress out.Buf(),out_size,bank.Buf()+4,UInt(bank.Size()-4)
  46. ?Not bmxng
  47. Local out:TBank=TBank.Create( out_size )
  48. uncompress out.Buf(),out_size,bank.Buf()+4,bank.Size()-4
  49. ?
  50. Return out
  51. End Function
  52. Function SplitUrl( url$,server$ Var,file$ Var )
  53. Local i=url.Find( "/",0 )
  54. If i<>-1
  55. server=url[..i]
  56. file=url[i..]
  57. Else
  58. server=url
  59. file="/"
  60. EndIf
  61. End Function