4 Replies Latest reply on Oct 28, 2008 1:20 PM by (Matt_Foster)

    Read Write Problems, Javascript

      Hello,

      I have had problems with a simple procedure. The grand scheme involves a lot more, so my example may seem trivial but this is where I've narrowed the problem down to. I cannot read an image file using the File object and write it back out as an image. Here is my test function, my targetengine for the script is session. When using the BINARY encoding the replicated file is the same size and appears almost identical but it simply won't be recognized as a valid jpg

      function readWrite(){
      var name = "/c/indesign_scripts/Winter.jpg";
      var f = new File(name);
      var encoding = "BINARY";
      if(!File.isEncodingAvailable(encoding))
      alert("You're using an unsupported encoding");

      f.encoding = encoding;
      f.open("r");
      var payload = f.read();

      var f2 = new File("/c/indesign_scripts/Winter-1.jpg");
      f2.open("w");
      var bool = f2.write(payload);
      if(!bool)
      alert(f2.error);
      //*/

      }

      Thanks in advance for any advice,
      Matt