How to decode heatshrink

Posted on
  • I compress an object: schedule = require("heatshrink").compress(JSON.parse(require("Storage").read("CustomSchedule.json")));
    Printing the value of schedule returns new Uint8Array([0, 2]).buffer.
    I then decompress using console.log(require("heatshrink").decompress(schedule)); and get new ArrayBuffer(2).
    How can I convert the ArrayBuffer back to an object?

  • I'm afraid you can't, since heatshrink compresses only a sequence of bytes, not a structure.

    If you want to compress it and get the data back, you'll need to compress the JSON, so:

    schedule = require("heatshrink").compress(require("Storage").read("CustomSchedul­e.json"));
    

    However this may be counterproductive. require("Storage").read effectively 'memory maps' the JSON that's in flash memory, so it doesn't actually use up any RAM when it's sitting there as a string.

    It's only when you decode it with JSON.parse that it ends up using a bunch of memory

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

How to decode heatshrink

Posted by Avatar for Asynchronous @Asynchronous

Actions