Skip to content

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
sverdlov93 committed Mar 6, 2024
1 parent 5aef0ea commit 9f2f40f
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions http/multipart/multipart.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package multipart

import (
"fmt"
fileutils "github.com/jfrog/gofrog/io"
"io"
"mime/multipart"
"os"
)

type FileWriterFunc func(fileName string) (io.WriteCloser, error)

func ReadFromStream(multipartReader *multipart.Reader, fileWriterFunc FileWriterFunc) error {
for {
// Read the next file streamed from client
fileReader, err := multipartReader.NextPart()
if err != nil {
if err == io.EOF {
break
}
return fmt.Errorf("failed to read file: %w", err)
}
fileName := fileReader.FileName()
fileWriter, err := fileWriterFunc(fileName)
if err != nil {
return err
}
defer fileutils.Close(fileWriter, &err)

// Stream file directly to disk
if _, err = io.Copy(fileWriter, fileReader); err != nil {
return fmt.Errorf("failed writing '%s' file: %w", fileName, err)
}
}
return nil
}

func exampleFunc(filepath string) (fileWriter io.WriteCloser, err error) {

Check failure on line 38 in http/multipart/multipart.go

View workflow job for this annotation

GitHub Actions / Static-Check

func `exampleFunc` is unused (unused)

Check failure on line 38 in http/multipart/multipart.go

View workflow job for this annotation

GitHub Actions / Static-Check

func `exampleFunc` is unused (unused)
fileWriter, err = os.Create(filepath)
if err != nil {
return nil, fmt.Errorf("create file: %w", err)
}
return
}

func myMain(filepath string) {

Check failure on line 46 in http/multipart/multipart.go

View workflow job for this annotation

GitHub Actions / Static-Check

`myMain` - `filepath` is unused (unparam)

Check failure on line 46 in http/multipart/multipart.go

View workflow job for this annotation

GitHub Actions / Static-Check

`myMain` - `filepath` is unused (unparam)
ReadFromStream(nil, exampleFunc)

Check failure on line 47 in http/multipart/multipart.go

View workflow job for this annotation

GitHub Actions / Static-Check

Error return value is not checked (errcheck)

Check failure on line 47 in http/multipart/multipart.go

View workflow job for this annotation

GitHub Actions / Static-Check

Error return value is not checked (errcheck)
}

0 comments on commit 9f2f40f

Please sign in to comment.