MCPcopy
hub / github.com/pocketbase/pocketbase / NewFileFromBytes

Function NewFileFromBytes

tools/filesystem/file.go:64–78  ·  view source on GitHub ↗

NewFileFromBytes creates a new File instance from the provided byte slice.

(b []byte, name string)

Source from the content-addressed store, hash-verified

62
63// NewFileFromBytes creates a new File instance from the provided byte slice.
64func NewFileFromBytes(b []byte, name string) (*File, error) {
65 size := len(b)
66 if size == 0 {
67 return nil, errors.New("cannot create an empty file")
68 }
69
70 f := &File{}
71
72 f.Reader = &BytesReader{b}
73 f.Size = int64(size)
74 f.OriginalName = name
75 f.Name = normalizeName(f.Reader, f.OriginalName)
76
77 return f, nil
78}
79
80// NewFileFromMultipart creates a new File from the provided multipart header.
81func NewFileFromMultipart(mh *multipart.FileHeader) (*File, error) {

Callers 15

TestFileAsMapFunction · 0.92
TestNewFileFromBytesFunction · 0.92
TestFileFieldDriverValueFunction · 0.92
TestFileFieldFindGetterFunction · 0.92
TestFileFieldInterceptFunction · 0.92
TestFileFieldInterceptTxFunction · 0.92
TestUploadedFileSizeFunction · 0.92
TestUploadedFileMimeTypeFunction · 0.92

Calls 1

normalizeNameFunction · 0.85

Tested by 15

TestFileAsMapFunction · 0.74
TestNewFileFromBytesFunction · 0.74
TestFileFieldDriverValueFunction · 0.74
TestFileFieldFindGetterFunction · 0.74
TestFileFieldInterceptFunction · 0.74
TestFileFieldInterceptTxFunction · 0.74
TestUploadedFileSizeFunction · 0.74
TestUploadedFileMimeTypeFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…