Move Close
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 56s

This commit is contained in:
Alexandre Bruyant 2024-01-07 22:19:37 +01:00
parent ba717cfdb6
commit dfd4fc1ecf

38
main.go
View File

@ -108,14 +108,15 @@ func main() {
q := req.URL.Query()
q.Add("wrap-with-directory", "true")
q.Add("progress", "false")
q.Add("stream-true", "false")
req.URL.RawQuery = q.Encode()
mwriter := NewIpfsMultipartWriter(writer)
req.Header.Add("Content-Type", mwriter.FormDataContentType())
go func() {
defer mwriter.Close()
defer writer.Close()
defer mwriter.Close()
err = filepath.Walk(path, func(innerPath string, info fs.FileInfo, err error) error {
if err != nil {
@ -123,27 +124,24 @@ func main() {
}
if info.IsDir() {
// _, err = mwriter.CreateIpfsDirectoryPart(innerPath)
// if err != nil {
// return err
// }
} else {
relPath, _ := filepath.Rel(path, innerPath)
w, err := mwriter.CreateIpfsFilePart(url.QueryEscape(fmt.Sprintf("/%v", relPath)))
if err != nil {
return err
}
return nil
}
fileReader, err := os.Open(innerPath)
if err != nil {
return err
}
defer fileReader.Close()
relPath, _ := filepath.Rel(path, innerPath)
w, err := mwriter.CreateIpfsFilePart(url.QueryEscape(fmt.Sprintf("/%v", relPath)))
if err != nil {
return err
}
written, err := io.Copy(w, fileReader)
if err != nil {
return fmt.Errorf("error copying %s (%d bytes written): %v", innerPath, written, err)
}
fileReader, err := os.Open(innerPath)
if err != nil {
return err
}
defer fileReader.Close()
written, err := io.Copy(w, fileReader)
if err != nil {
return fmt.Errorf("error copying %s (%d bytes written): %v", innerPath, written, err)
}
return nil