window.safeImmutableData.read no data returned?


#1

I am trying to run the example from here with mock routing and it seems to be giving back empty data. The size example shows the correct size of the data. I removed the call to toString and you can see it is an empty array buffer. I was expecting the string my immutable data. Can anyone else verify?

// Read data from an ImmutableData:
window.safeImmutableData.create(appHandle)
   .then((idWriterHandle) => window.safeImmutableData.write(idWriterHandle, 'my immutable data')
      .then(_ => window.safeCipherOpt.newPlainText(appHandle)
         .then((cipherOptHandle) => window.safeImmutableData.closeWriter(idWriterHandle, cipherOptHandle))
      )
   )
   .then((addr) => window.safeImmutableData.fetch(appHandle, addr))
   .then((idReaderHandle) => window.safeImmutableData.read(idReaderHandle))
   .then((data) => console.log('ImmutableData data read: ', data));

output

Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
VM189:9 ImmutableData data read:  ArrayBuffer {}

Sorry this isn’t a complete example but in any SAFE app this should run in the debug console pretty easily.


#2

I don’t have time to examine in detail, so this may be off, but it reminds me of when I first tried reading data.

The issue, from memory (so beware :wink:), was that the returned data was an ArrayBuffer (I think) and that I needed to access it using something else - an ArrayBufferView (or something like that). Anyway, maybe enough hints there for you to tell if this is where to look!?


#3

I see that there is probably a type issue there but as you can see in the output the array buffer doesn’t have any data in it, not even the unicode bytes that i thought i might see…


#4

I just tested this in my web API playground and I see that the ArrayBuffer has the expected 17 byte length.

I saved the logged ArrayBuffer to a global variable and read it as UTF-8 with String.fromCharCode.apply(null, new Uint8Array(temp1))


#5

Great!

This is the final solution, you can paste this in a JS console with window.appHandle defined in a valid way and see the response!

window.safeImmutableData.create(appHandle)
   .then((idWriterHandle) => window.safeImmutableData.write(idWriterHandle, 'my immutable data')
      .then(_ => window.safeCipherOpt.newPlainText(appHandle)
         .then((cipherOptHandle) => window.safeImmutableData.closeWriter(idWriterHandle, cipherOptHandle))
      )
   )
   .then((addr) => window.safeImmutableData.fetch(appHandle, addr))
   .then((idReaderHandle) => window.safeImmutableData.read(idReaderHandle))
   .then((data) => console.log('ImmutableData data read: ', String.fromCharCode.apply(null, new Uint8Array(data))));

#6

This topic was automatically closed after 60 days. New replies are no longer allowed.