Skip to content

Commit 8431ff2

Browse files
feat(Filescan): Allow passing scan parameters (#31)
* feat(Filescan): Allow passing scan parameters * Update filescan.go Co-authored-by: Marta Gómez Macías <[email protected]> --------- Co-authored-by: Marta Gómez Macías <[email protected]>
1 parent f13ce7e commit 8431ff2

File tree

1 file changed

+42
-9
lines changed

1 file changed

+42
-9
lines changed

filescan.go

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,8 @@ type FileScanner struct {
4444
cli *Client
4545
}
4646

47-
// Scan sends a file to VirusTotal for scanning. The file content is read from
48-
// the r io.Reader and sent to VirusTotal with the provided file name which can
49-
// be left blank. The function also sends a float32 through the progress channel
50-
// indicating the percentage of the file that has been already uploaded. The
51-
// progress channel can be nil if the caller is not interested in receiving
52-
// upload progress updates. An analysis object is returned as soon as the file
53-
// is uploaded.
54-
func (s *FileScanner) Scan(r io.Reader, filename string, progress chan<- float32) (*Object, error) {
55-
47+
func (s *FileScanner) scanWithParameters(
48+
r io.Reader, filename string, progress chan<- float32, parameters map[string]string) (*Object, error) {
5649
var uploadURL *url.URL
5750
var payloadSize int64
5851

@@ -70,6 +63,14 @@ func (s *FileScanner) Scan(r io.Reader, filename string, progress chan<- float32
7063
return nil, err
7164
}
7265

66+
if parameters != nil {
67+
for key, val := range parameters {
68+
if err := w.WriteField(key, val); err != nil {
69+
return nil, err
70+
}
71+
}
72+
}
73+
7374
w.Close()
7475

7576
if payloadSize > maxFileSize {
@@ -114,6 +115,38 @@ func (s *FileScanner) Scan(r io.Reader, filename string, progress chan<- float32
114115
return analysis, nil
115116
}
116117

118+
// ScanParameters sends a file to VirusTotal for scanning. The file content is
119+
// read from the r io.Reader and sent to VirusTotal with the provided file name
120+
// which can be left blank. The function also sends a float32 through the
121+
// progress channel indicating the percentage of the file that has been already
122+
// uploaded. The progress channel can be nil if the caller is not interested in
123+
// receiving upload progress updates. An analysis object is returned as soon as
124+
// the file is uploaded. Additional parameters can be passed to the scan
125+
// by using the parameters map[string]string argument.
126+
func (s *FileScanner) ScanParameters(
127+
r io.Reader, filename string, progress chan<- float32, parameters map[string]string) (*Object, error) {
128+
return s.scanWithParameters(r, filename, progress, parameters)
129+
}
130+
131+
// ScanFileWithParameters sends a file to VirusTotal for scanning. This function
132+
// is similar to ScanWithParameters but it receives an *os.File instead of a
133+
// io.Reader and a file name.
134+
func (s *FileScanner) ScanFileWithParameters(
135+
f *os.File, progress chan<- float32, parameters map[string]string) (*Object, error) {
136+
return s.scanWithParameters(f, f.Name(), progress, parameters)
137+
}
138+
139+
// Scan sends a file to VirusTotal for scanning. The file content is read from
140+
// the r io.Reader and sent to VirusTotal with the provided file name which can
141+
// be left blank. The function also sends a float32 through the progress channel
142+
// indicating the percentage of the file that has been already uploaded. The
143+
// progress channel can be nil if the caller is not interested in receiving
144+
// upload progress updates. An analysis object is returned as soon as the file
145+
// is uploaded.
146+
func (s *FileScanner) Scan(r io.Reader, filename string, progress chan<- float32) (*Object, error) {
147+
return s.scanWithParameters(r, filename, progress, nil)
148+
}
149+
117150
// ScanFile sends a file to VirusTotal for scanning. This function is similar to
118151
// Scan but it receive an *os.File instead of a io.Reader and a file name.
119152
func (s *FileScanner) ScanFile(f *os.File, progress chan<- float32) (*Object, error) {

0 commit comments

Comments
 (0)