Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handling for ArrayBuffer data #7

Open
rwv opened this issue Oct 11, 2018 · 7 comments
Open

Add handling for ArrayBuffer data #7

rwv opened this issue Oct 11, 2018 · 7 comments

Comments

@rwv
Copy link
Contributor

rwv commented Oct 11, 2018

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

@Polarisation
Copy link
Owner

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
}

@rwv
Copy link
Contributor Author

rwv commented Oct 12, 2018

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

@Polarisation
Copy link
Owner

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

Along with the replacer function for JSON.stringify()

@Polarisation
Copy link
Owner

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

@rwv
Copy link
Contributor Author

rwv commented Dec 17, 2018

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

@rwv rwv mentioned this issue Jul 21, 2019
@Polarisation Polarisation changed the title Unable to export indexeddb with ArrayBuffer data Add handling for ArrayBuffer data Jun 4, 2020
@Miaourt
Copy link

Miaourt commented Sep 20, 2020

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

@Polarisation
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants