/
writers.go
99 lines (90 loc) · 2.93 KB
/
writers.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Copyright (c) 2019 Alec Randazzo
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/
package GoFor_MFT_Parser
import (
"fmt"
"io"
"strconv"
"sync"
)
// Interface for result writers to allow for output format extensibility.
type ResultWriter interface {
ResultWriter(streamer io.Writer, outputChannel *chan UsefulMftFields, waitGroup *sync.WaitGroup)
}
// Receiver used with the ResultWriter method that would write the csv results to csv.
type CsvResultWriter struct{}
// This method that would write the csv results to csv.
func (csvResultWriter *CsvResultWriter) ResultWriter(streamer io.Writer, outputChannel *chan UsefulMftFields, waitGroup *sync.WaitGroup) {
delimiter := "|"
csvHeader := []string{
"Record Number",
"directory Flag",
"System File Flag",
"Hidden Flag",
"Read-only Flag",
"Deleted Flag",
"File Path",
"File Name",
"File Size",
"File Created",
"File Modified",
"File Accessed",
"File Entry Modified",
"FileName Created",
"FileName Modified",
"Filename Accessed",
"Filename Entry Modified",
"\n",
}
// Write CSV header
headerSize := len(csvHeader)
for index, header := range csvHeader {
_, _ = streamer.Write([]byte(header))
if index < headerSize-2 {
_, _ = streamer.Write([]byte(delimiter))
}
}
openChannel := true
for {
var file UsefulMftFields
file, openChannel = <-*outputChannel
if openChannel == false {
break
}
csvRow := []string{
fmt.Sprint(file.RecordNumber), //Record Number
strconv.FormatBool(file.DirectoryFlag), //directory Flag
strconv.FormatBool(file.SystemFlag), //System file flag
strconv.FormatBool(file.HiddenFlag), //Hidden flag
strconv.FormatBool(file.ReadOnlyFlag), //Read only flag
strconv.FormatBool(file.DeletedFlag), //Deleted Flag
file.FilePath, //File directory
file.FileName, //File Name
strconv.FormatUint(file.PhysicalFileSize, 10), // File Size
file.SiCreated.Format("2006-01-02T15:04:05Z"), //File Created
file.SiModified.Format("2006-01-02T15:04:05Z"), //File Modified
file.SiAccessed.Format("2006-01-02T15:04:05Z"), //File Accessed
file.SiChanged.Format("2006-01-02T15:04:05Z"), //File entry Modified
file.FnCreated.Format("2006-01-02T15:04:05Z"), //FileName Created
file.FnModified.Format("2006-01-02T15:04:05Z"), //FileName Modified
file.FnAccessed.Format("2006-01-02T15:04:05Z"), //FileName Accessed
file.FnChanged.Format("2006-01-02T15:04:05Z"), //FileName Entry Modified
"\n", // Newline
}
csvRowSize := len(csvRow)
for index, item := range csvRow {
_, _ = streamer.Write([]byte(item))
if index < csvRowSize-2 {
_, _ = streamer.Write([]byte(delimiter))
}
}
}
waitGroup.Done()
return
}