The example given for Immutable.Writer() in the node API documentation doesn't work

Under Home - Documentation there is a neat little example given.

// write new data to the network
app.immutableData.create().then((writer)=> {
 return writer.write("some string\n")
  .then(() => writer.write("second string"))
  .then(() => writer.close())
  .then((address) => app.immutableData.fetch(address)
    .then((reader) => reader.read()
      .then( (payload) => {
        should(payload).equals("some string\nsecond string");
      })
    ))
})

Sadly there is an issue with it. I am using version 0.5.3 of the API and I am getting this error…

TypeError: Cannot read property ‘ref’ of undefined

It looks to me that Home - Documentation needs a cipherOpt to function. What is confusing is the documentation says that it takes two parameters, close(cipherOpt: any, the: CipherOpt). When looking at the code it only takes one parameter…

  /**
  * Close and write the immutable Data to the network.
  *
  * @param {CipherOpt} the Cipher Opt to encrypt data with
  * @returns {Promise<String>} the address to the data once written to the network
  */

I am assuming this is because the documentation is out of sync with the code. Or maybe I am being incredibly silly, it has happened once or twice before. Could anyone give a suggestion on how this example would be updated? I have tried changing the line to include a newPlainText() inside the close() call but to no avail.

2 Likes

Hi @DaBrown95, for some reason when the documentation HTML page is automatically generated is getting malformed, as you already noticed it the close method expects one argument, the CipherOpt to encrypt the data with, therefore the example snippet is incomplete.

I just sent a PR to fix this in the documentation (I’ll try to fix the other part of the documentation where args list is corrupted/malformed), you can see the new example does use newPlainText() as you mentioned it and it works fine for me. Please take a look and let me know if that’s how you also tried it and still doesn’t work: doc/ImmutableData: Fix snippet code of ImmutableData.writer function by bochaco · Pull Request #198 · maidsafe-archive/safe_app_nodejs · GitHub

It seems this time you won’t increase your stats :smile: :smiley:

3 Likes

Thanks for the swift reply!


Yeah that worked perfectly for me as you can see! ^

Phew, Can save that for another day! :stuck_out_tongue_winking_eye:

Thanks for sorting this, I can imagine this type of thing isn’t high up the priorities list so I appreciate it!

2 Likes