File size: 650 Bytes
2cae2a9
 
 
 
 
46fcec6
 
 
 
 
2cae2a9
46fcec6
 
 
 
2cae2a9
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { existsSync, promises as fs } from "node:fs"

// note: this function will never fail
export async function removeTemporaryFiles(filesPaths: string[]) {
  try {
    // Cleanup temporary files - you could choose to do this or leave it to the user
    await Promise.all(filesPaths.map(async (filePath) => {
      try {
        if (existsSync(filePath)) {
          await fs.rm(filePath)
        }
      } catch (err) {
        //
      }
    }))
  } catch (err) {
    // no big deal, except a bit of tmp file leak
    // although.. if delete failed, it could also indicate
    // that the file has already been cleaned-up, so even better!
  } 
}