feat: add copy file to local

This commit is contained in:
ᴍᴏᴏɴD4ʀᴋ
2022-04-11 19:57:40 +08:00
parent 46f2610a0a
commit dc06b1d69b
18 changed files with 83 additions and 258 deletions
+21
View File
@@ -1,8 +1,11 @@
package fileutil
import (
"fmt"
"io/ioutil"
"os"
"hack-browser-data/internal/item"
)
// FileExists checks if the file exists in the provided path
@@ -34,3 +37,21 @@ func ReadFile(filename string) (string, error) {
s, err := ioutil.ReadFile(filename)
return string(s), err
}
// CopyItemToLocal copies the file from the provided path to the local path
func CopyItemToLocal(itemPaths map[item.Item]string) error {
for i, path := range itemPaths {
// var dstFilename = item.TempName()
var filename = i.String()
// TODO: Handle read file error
d, err := ioutil.ReadFile(path)
if err != nil {
fmt.Println(err.Error())
}
err = ioutil.WriteFile(filename, d, 0777)
if err != nil {
return err
}
}
return nil
}