JScript read / write binaries

From , 5 Years ago, written in JavaScript, viewed 192 times.
URL https://pastebin.vip/view/14ad095e
  1. var bin = new Array(256);
  2.  
  3. for(var i=0;i<256;i++){
  4.  
  5.     bin[i]=String.fromCharCode(i);
  6.  
  7. }
  8.  
  9.  
  10.  
  11. function TestWrite(){
  12.  
  13.     var Stream = new ActiveXObject("ADODB.Stream");
  14.  
  15.     var adTypeBinary=1,adTypeText=2;
  16.  
  17.     Stream.Type = adTypeText;
  18.  
  19.     Stream.CharSet = "iso-8859-1";
  20.  
  21.     Stream.Open();
  22.  
  23.     //Stream.WriteText("\x00\x01\x02\xff\xff");
  24.  
  25.     for(var i=0;i<256;i++){
  26.  
  27.         Stream.WriteText(String.fromCharCode(i));
  28.  
  29.         //Stream.WriteText(bin[i]);
  30.  
  31.     }
  32.  
  33.     Stream.SaveToFile("c:\\windows\\temp\\test.bin", 2);
  34.  
  35.     Stream.Close();
  36.  
  37.     Stream = null;
  38.  
  39. }
  40.  
  41. function BinaryFile(filepath){
  42.  
  43.     var adTypeBinary=1,adTypeText=2;
  44.  
  45.     var adSaveCreateNotExist=1,adSaveCreateOverWrite=2;
  46.  
  47.     var adReadAll=-1,adReadLine=-2;
  48.  
  49.     this.path=filepath;
  50.  
  51.     this.WriteAll = function(content){
  52.  
  53.         var Stream = new ActiveXObject("ADODB.Stream");
  54.  
  55.         Stream.Type = adTypeText;
  56.  
  57.         Stream.CharSet = "iso-8859-1";
  58.  
  59.         Stream.Open();
  60.  
  61.         Stream.WriteText(content);
  62.  
  63.         Stream.SaveToFile(this.path, adSaveCreateOverWrite);
  64.  
  65.         Stream.Close();
  66.  
  67.         Stream = null;
  68.  
  69.     }
  70.  
  71.     this.ReadAll = function(){
  72.  
  73.         var Stream = new ActiveXObject("ADODB.Stream");
  74.  
  75.         Stream.Type = adTypeText;
  76.  
  77.         Stream.CharSet = "iso-8859-1";
  78.  
  79.         Stream.Open();
  80.  
  81.         Stream.LoadFromFile(this.path);
  82.  
  83.         var content = Stream.ReadText(adReadAll);
  84.  
  85.         Stream.Close();
  86.  
  87.         Stream = null;
  88.  
  89.         return content;
  90.  
  91.     }
  92.  
  93. }
  94.  
  95. // Example Code
  96.  
  97. /*
  98.  
  99. var crFolder = 'C:/Temp/cr'
  100.  
  101. var bf1=new BinaryFile(crFolder+"/PCDV0026.JPG");
  102.  
  103. var bf2=new BinaryFile(crFolder+"/PCDV0026_.JPG");
  104.  
  105. bf2.WriteAll(bf1.ReadAll());
  106.  
  107. */
  108. //javascript/5655

Reply to "JScript read / write binaries"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website