another file read problem [solved]

Posted on
  • I do not seem to be able to read a file after opening it - what am I doing wrong?

    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 ****/
    
      if (Storage.write('4testing','Hello, World!')) {
        print('file "4testing" was successfully created');
      } else {
        print('file "4testing" could not be created');
      }
      compareFileWith('Hello, World!');
    
      let TestFile;
    
    /**** read file ****/
    
      TestFile = Storage.open('4testing','r');
    
      let readText = TestFile.read(4);
      if (readText !== 'Hello') {
        print('>>>> reading "4testing" failed');
        print('>>>> expected "Hello", got "' + readText + '"');
      }
    

    readText turns out to be undefined

  • The docs on the Bangle.js site haven't been updated yet, but: https://github.com/espruino/Espruino/blo­b/master/src/jswrap_storage.c#L406

    Basically you can't combine Storage.write with the files created using Storage.open, since they're handled in a different way.

  • Oh, good to know...seems that I've been just a little bit too naive...

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

another file read problem [solved]

Posted by Avatar for Andreas_Rozek @Andreas_Rozek

Actions