holepunchto / hyperdrive

Hyperdrive is a secure, real time distributed file system
Apache License 2.0
1.86k stars 135 forks source link

FileNotFound: error right after writing the file, the file exists but still getting error #329

Closed ducksandgoats closed 1 year ago

ducksandgoats commented 2 years ago

here is an explanation of what the issue is

first one writes the files second one checks if the file was written

async function testone(){
       const saveIter = []
        saveIter.push(
          Promise.race([
            new Promise((resolve, reject) => {
              const source = Readable.from(fileData)
              const destination = app.Hyperdrive(mid.useHost).createWriteStream(usePath)
              source.pipe(destination)
              source.once('error', reject)
              destination.once('error', reject)
              source.once('end', resolve)
            }),
            new Promise((resolve, reject) => setTimeout(reject, timer))
          ])
        )
        await Promise.all(saveIter)
}

async function testtwo(){
        const prop = // get the hyperdrive key
        let useData = await app.Hyperdrive(main.useHost).stat(i)
        useData = Array.isArray(useData) ? useData[0] : useData
        useData.pid  = prop
        useData.file = i
        useData.link = 'hyper://' + useData.pid + useData.file
        result.push(useData)
}

await testone()

await testtwo()

after running this, i get the file not found error FileNotFound: No such file or directory: '/some-image.png' but right after the code blocks run, i stop the process(ctrl+c) and re-run it then it finds the file. so i get this error only after running the second async functions right after the first async function in the same process.