indexeddb-export-import
indexeddb-export-import copied to clipboard
Add handling for ArrayBuffer data
ArrayBuffer should be exported via some tricky way instead of JSON.stringify.
I think it can be done by passing a replace function to JSON.stringify, so it would output something like this:
{
"IndexedDBExportImport_Type": 'ArrayBuffer',
"base64": "" // base64 encoded data here
}
I think the point is how to get this thing done gracefully. After adding the type of exported data, you could not simply use JSON.parse(jsonString); to restore the data. Therefore, a export and restore function for each is needed.
exported function maybe like this?
func_dict={
"ArrayBuffer":{
"type": ArrayBuffer,
"func": func_to_exported_arraybuffer,
}
}
function(data_to_exported) {
forEach(func_dict, function(func_item){
if (data_to_exported instanceof func_item["type"]){
return {
'type': func_item["type"],
'data': func_to_exported_arraybuffer(data_to_exported)
}
}
})
return {
'type': object,
'data': JSON.stringify(data_to_exported)
}
}
It should be possible with JSON.parse() using a reviver function
Along with the replacer function for JSON.stringify()
I've no plans to work on this but I'd accept a pull request implementing the feature
Sorry, i've no plan to work on this right now but thank you anyway!
Hello, kinda digging this up, and It might be a bit out of place, but re-doing https://www.npmjs.com/package/typeson or even using it might be a good solution to handle all the exotic types presents in indexeddb
As earlier, I'm happy to accept a pull request but won't be working on this myself.
For people who need this functionality now, there's a Dexie extension, dexie-export-import, that supports a range of types. The main disadvantage is that it's not as lightweight.