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

[Feature Request] ReadOnly Box #43

Closed
Afsar-Pasha opened this issue Sep 10, 2019 · 10 comments
Closed

[Feature Request] ReadOnly Box #43

Afsar-Pasha opened this issue Sep 10, 2019 · 10 comments
Labels
enhancement New feature or request
Milestone

Comments

@Afsar-Pasha
Copy link
Contributor

Afsar-Pasha commented Sep 10, 2019

Request for ReadOnly Box which can read data without write permission(Ex.from flutter assets)

@Afsar-Pasha Afsar-Pasha added the enhancement New feature or request label Sep 10, 2019
@simc
Copy link
Member

simc commented Sep 10, 2019

I will look into this...

@bolasim
Copy link

bolasim commented Sep 11, 2019

I would also find this super helpful. Let me know if you need a hand.

@bolasim
Copy link

bolasim commented Sep 18, 2019

Any update on this? Also, if this is implemented, can you read directly from assets (for flutter) instead of having to copy over the box?

@simc
Copy link
Member

simc commented Sep 18, 2019

@re-bola I'm still working on this and yes you will be able to open a box directly from the assets. It will look somehow like this:

var bytes = rootBundle.load('assets/myBox.hive');
var box = Hive.openBoxFromBytes('myBox', bytes);

Would that be okay?

@bolasim
Copy link

bolasim commented Sep 18, 2019

Looks good. Will it still support LazyBoxes?

@simc
Copy link
Member

simc commented Sep 18, 2019

Not in combination with read only boxes from bytes. It makes no sense since you cannot write to boxes from bytes anyways...

But the regular lazy boxes will still be there...

@simc simc added this to the 1.1.0 milestone Oct 11, 2019
@simc simc added the hive label Oct 11, 2019
@simc
Copy link
Member

simc commented Oct 16, 2019

This has been resolved in v1.1.0. You can use Hive.openBoxFromBytes().

@X-Wei
Copy link

X-Wei commented Dec 18, 2021

Seems openBoxFromBytes() method is not present in hive v2.0 -- how can we open a box in read-only mode now?

@fredrikbaberg
Copy link

fredrikbaberg commented Dec 20, 2021

@X-Wei I think the bytes argument should be used now. Not sure where I saw it described, but it's what I'm using in my current project. You could try the following code snippet; I've only tested it targeting Windows in debug mode but hope it helps.

var _bytes = await rootBundle
            .load(path)
            .then((value) => value.buffer.asUint8List());
        _box = await Hive.openBox(
          name,
          bytes: _bytes,
        );

@X-Wei
Copy link

X-Wei commented Jan 22, 2022

Thanks @fredrikbaberg !

But explicitly adding read-only boxes would be helpful, e.g. we could make concurrent access to read-only boxes possible. @leisim WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants