RangerMauve / hyper-sdk

Make your own hyper apps!
https://www.youtube.com/watch?v=HyHk4aImd_I&list=PL7sG5SCUNyeYx8wnfMOUpsh7rM_g0w_cu&index=20
MIT License
290 stars 46 forks source link

Why does the sdk create `uls_scratch` directory? #24

Closed e-e-e closed 4 years ago

e-e-e commented 4 years ago

I am a bit confused. I am trying to create a new dat with via the promise syntax and it is creating a directory uls_scratch within my current working directory, but apparently not creating a folder for storing the dat data.

const { DatArchive, destroy } = require("dat-sdk/auto");

async function main() {
  const archive = await DatArchive.create({ title: "My Archive" });
  await archive.writeFile("/example.txt", "Hello World!");
  destroy();
}
main();

What is this directory and why is it not cleaned up? Where is the actually data getting stored? Or does this use RAM?

RangerMauve commented 4 years ago

Oh dang. The folder is created as part of universal-localstorge I was trying to figure out a unified API for tracking saved keys between the browser and Node.

The actual Dat data storage is using universal-dat-storage. It uses the env-paths module to find storage on your platform for the app. On Windows it's inside ~/AppData/Roaming/Dat, on MacOS it's on ~/Library/Application Support/dat, and on Linux it should be somewhere in ~/.local. You can find more details in the source of that module. :) https://github.com/sindresorhus/env-paths/blob/master/index.js

e-e-e commented 4 years ago

It might be worth forking that module in this case. It looks relatively simple, and also kind of unmaintained. That would enable this SDK to have more control over the generation of temp files, and most importantly also clean up after itself.

RangerMauve commented 4 years ago

I might have time to do it next week, but in the meantime, a PR with a forked version of the module would be very much appreciated. 💜

dpaez commented 4 years ago

Is the fork necessary? Because it would be another module to maintain. env-paths has a property to access a temporal directory. Maybe the only thing to consider is the portability of using something like this. But this would only be a concern if we consider other dat ports like datcxx or the rust version (which are on an early stage).

Why it's not being cleaned after use it is because it's not treated as a temporal directory. dats are being stored in the user's home and the home dir is obtained by using env-paths. :v:

RangerMauve commented 4 years ago

@dpaez I think what @e-e-e meant was that they'd fork the universal-localstorage module to prevent it from creating this uls_scratch directory, not that they'd fork env-paths.

dpaez commented 4 years ago

alright, that is way better ^_^

RangerMauve commented 4 years ago

Messing with this now. Planning to make it store in the same place as the dats