• Sorry for bothering you - but I am completely unable to get even simple file operations working.

    The following code

    const Storage = require('Storage');
      function compareFileWith (expectedContent) {
        if (Storage.read('4testing') != expectedContent) {
          print('>>>> file does not look as expected');
          print('>>>> expected "' + expectedContent + '"');
          print('>>>> got "' + Storage.read('4testing') + '"');
        }
      }
    
    /**** create file ****/
    
      let TestFile = Storage.open('4testing','w');
    
      TestFile.write('Hello, World!');
      compareFileWith('Hello, World!');
    
    /**** read file ****/
    
      TestFile = Storage.open('4testing','r');
    
      let readText = TestFile.read(5);
      if (readText != 'Hello') {
        print('>>>> reading "4testing" failed');
        print('>>>> expected "Hello", got "' + readText + '"');
      }
    
      TestFile.read(2); // skip ', '
    
      readText = TestFile.read(5);
      if (readText != 'World') {
        print('>>>> reading "4testing" failed');
        print('>>>> expected "World", got "' + readText + '"');
      }
    
      TestFile.read(2); // skip '!' and go beyond EOF
      print('read after EOF: "' + TestFile.read(4) + '"');
    
    /**** write file ****/
    
      TestFile = Storage.open('4testing','w');
    
      TestFile.write('Welcome');
      compareFileWith('Welcome');
    
      TestFile.write(', World!');
      compareFileWith('Welcome, World!');
    
    /**** extend file ****/
    
      TestFile = Storage.open('4testing','a');
    
      TestFile.write('\nHere I am!');
      compareFileWith('Welcome, World!\nHere I am!');
    print('finished');
    

    produces this output

    read after EOF: "undefined"
    >>>> file does not look as expected
    >>>> expected "Welcome"
    >>>> got "Hello, World!"
    >>>> file does not look as expected
    >>>> expected "Welcome, World!"
    >>>> got "Hello, World!"
    >>>> file does not look as expected
    >>>> expected "Welcome, World!
    Here I am!"
    >>>> got "Hello, World!"
    finished
    

    which basically means that an existing file can not be overwritten using Storage.open(filename,'w') followed by file.write(newcontent).

    Does anybody see what I'm doing wrong?

About