indexeddb-export-import icon indicating copy to clipboard operation
indexeddb-export-import copied to clipboard

Add handling for ArrayBuffer data

Open rwv opened this issue 7 years ago • 7 comments

ArrayBuffer should be exported via some tricky way instead of JSON.stringify.

rwv avatar Oct 11 '18 01:10 rwv

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
}

Polarisation avatar Oct 11 '18 18:10 Polarisation

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)
        }
}

rwv avatar Oct 12 '18 06:10 rwv

It should be possible with JSON.parse() using a reviver function

Along with the replacer function for JSON.stringify()

Polarisation avatar Oct 12 '18 08:10 Polarisation

I've no plans to work on this but I'd accept a pull request implementing the feature

Polarisation avatar Nov 29 '18 13:11 Polarisation

Sorry, i've no plan to work on this right now but thank you anyway!

rwv avatar Dec 17 '18 06:12 rwv

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

Miaourt avatar Sep 20 '20 19:09 Miaourt

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.

Polarisation avatar Sep 21 '20 03:09 Polarisation