-
Notifications
You must be signed in to change notification settings - Fork 520
/
filedata.go
71 lines (61 loc) · 1.77 KB
/
filedata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// A facebook graph api client in go.
// https://github.com/huandu/facebook/
//
// Copyright 2012, Huan Du
// Licensed under the MIT license
// https://github.com/huandu/facebook/blob/master/LICENSE
package facebook
import (
"io"
)
// BinaryData represents binary data from a given source.
type BinaryData struct {
Filename string // filename used in multipart form writer.
Source io.Reader // file data source.
ContentType string // content type of the data.
}
// BinaryFile represents a file on disk.
type BinaryFile struct {
Filename string // filename used in multipart form writer.
Path string // path to file. must be readable.
ContentType string // content type of the file.
}
// Data creates new binary data holder.
func Data(filename string, source io.Reader) *BinaryData {
return &BinaryData{
Filename: filename,
Source: source,
}
}
// DataWithContentType creates new binary data holder with arbitrary content type.
func DataWithContentType(filename string, source io.Reader, contentType string) *BinaryData {
return &BinaryData{
Filename: filename,
Source: source,
ContentType: contentType,
}
}
// File creates a binary file holder.
func File(filename string) *BinaryFile {
return &BinaryFile{
Filename: filename,
}
}
// FileAlias creates a binary file holder and specific a different path for reading.
func FileAlias(filename, path string) *BinaryFile {
return &BinaryFile{
Filename: filename,
Path: path,
}
}
// FileAliasWithContentType creates a new binary file holder with arbitrary content type.
func FileAliasWithContentType(filename, path, contentType string) *BinaryFile {
if path == "" {
path = filename
}
return &BinaryFile{
Filename: filename,
Path: path,
ContentType: contentType,
}
}