-
Notifications
You must be signed in to change notification settings - Fork 28
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 opts.persistentKey (to avoid writing key to disk) #43
base: main
Are you sure you want to change the base?
Changes from all commits
cb07362
6d554d6
dcf8f61
49b4a6f
c7097b6
1fd350c
e405776
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ module.exports = class Corestore extends EventEmitter { | |
this.cores = root ? root.cores : new Map() | ||
this.cache = !!opts.cache | ||
this.primaryKey = opts.primaryKey || null | ||
this.persistentKey = opts.persistentKey !== false | ||
|
||
this._keyStorage = null | ||
this._namespace = opts.namespace || DEFAULT_NAMESPACE | ||
|
@@ -90,7 +91,7 @@ module.exports = class Corestore extends EventEmitter { | |
if (err && err.code !== 'ENOENT') return reject(err) | ||
if (err || st.size < 32 || this._overwrite) { | ||
const key = this.primaryKey || crypto.randomBytes(32) | ||
return this._keyStorage.write(0, key, err => { | ||
return this._keyStorage.write(0, this.persistentKey ? key : b4a.alloc(0), err => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont write anything if you are not persisting. just return before instead and resolve There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, the issue is that we still need to lock from the storage There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although I don't remember if without writing then the file exists anyway, maybe it does, will check later! |
||
if (err) return reject(err) | ||
return resolve(key) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could use a better name i think.