Add yt-downloader

This commit is contained in:
2021-12-21 23:05:00 +01:00
committed by kjuulh
parent 0d3fae2ca5
commit 4b9583b08f
17 changed files with 449 additions and 134 deletions

31
api/pkg/files/move.go Normal file
View File

@@ -0,0 +1,31 @@
package files
import (
"fmt"
"io"
"os"
)
func MoveFile(sourcePath, destPath string) error {
inputFile, err := os.Open(sourcePath)
if err != nil {
return fmt.Errorf("couldn't open source file: %s", err)
}
outputFile, err := os.Create(destPath)
if err != nil {
inputFile.Close()
return fmt.Errorf("couldn't open dest file: %s", err)
}
defer outputFile.Close()
_, err = io.Copy(outputFile, inputFile)
inputFile.Close()
if err != nil {
return fmt.Errorf("writing to output file failed: %s", err)
}
// The copy was successful, so now delete the original file
err = os.Remove(sourcePath)
if err != nil {
return fmt.Errorf("failed removing original file: %s", err)
}
return nil
}