ssbc / ssb-keys

keyfile operations for ssb
36 stars 26 forks source link

Fix storage.js fallback logic to local-storage #36

Closed staltz closed 7 years ago

staltz commented 7 years ago

fs.readFileSync is not available in https://www.npmjs.com/package/level-filesystem which is what React Native uses when shimming fs (because it cannot support sync APIs). I figured that this line of code is checking (1) whether fs is available and (2) whether fs is actually a filesystem API. It seems for purpose (2) that readFile is enough. Or is there a reason for readFileSync?

With these changes, an fs object missing readFileSync would still work as long as loadSync is avoided and load is used instead.

dominictarr commented 7 years ago

The number 1 reason it's sync is because it's generally something that you only have to do once, at startup (like loading configuration). Making it be sync means you can avoid what would otherwise be another closure around your whole application. do you have access to localStorage in react-native?

dominictarr commented 7 years ago

merged into 7.0.6

staltz commented 7 years ago

do you have access to localStorage in react-native?

Unfortunately not, it's only the AsyncStorage.