You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: cmd/query_file_ea/query_file_ea.go
+12-6Lines changed: 12 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -17,15 +17,17 @@ import (
17
17
18
18
funcmain() {
19
19
vartargetPath, queryNamestring
20
-
vardump, extractbool
20
+
vardump, extract, stdoutbool
21
21
22
22
flag.StringVar(&targetPath, "target-path", "", "path of the file to query EA")
23
23
flag.StringVar(&queryName, "query-name", "", "names of EA to query, split by comma, if it is not given, query all EA from the file")
24
+
24
25
flag.BoolVar(&dump, "dump", false, "dump EA to console, this is enabled by default if no action is given")
25
26
flag.BoolVar(&extract, "extract", false, "extract EA to file(s) with according EaName")
27
+
flag.BoolVar(&stdout, "stdout", false, "extract EA into stdout")
26
28
27
29
flag.Usage=func() {
28
-
fmt.Fprintf(flag.CommandLine.Output(), "%s queries EA(Extended Attribute) from a file in NTFS(New Technology File System).\nUsage: %s -query-name [eaName1],[eaName2],... -extract [target path]\n or %s -target-path [target path] -query-name [eaName1],[eaName2],... -dump -extract\nThis program is supposed to work only in Windows.\n\n", os.Args[0], os.Args[0], os.Args[0])
30
+
fmt.Fprintf(flag.CommandLine.Output(), "%s queries EA(Extended Attribute) from a file in NTFS(New Technology File System).\nUsage: %s -query-name [eaName1],[eaName2],... -extract [target path]\n or %s -target-path [target path] -query-name [eaName1],[eaName2],... -dump -extract\nWrite EA value to stdout(for piping output): %s -stdout -target-path [target path] -query-name [eaName] | (process output)\n\n", os.Args[0], os.Args[0], os.Args[0], os.Args[0])
29
31
flag.PrintDefaults()
30
32
}
31
33
@@ -66,11 +68,15 @@ func main() {
66
68
}
67
69
68
70
ifextract {
69
-
err:=os.WriteFile(ea.EaName, ea.EaValue, 0777)
70
-
iferr!=nil {
71
-
fmt.Fprintf(os.Stderr, "Failed to write EA for %s into file: %v\n", ea.EaName, err)
71
+
ifstdout {
72
+
os.Stdout.Write(ea.EaValue)
72
73
} else {
73
-
fmt.Printf("Extracted EaValue in \"%s\"", ea.EaName)
74
+
err:=os.WriteFile(ea.EaName, ea.EaValue, 0777)
75
+
iferr!=nil {
76
+
fmt.Fprintf(os.Stderr, "Failed to write EA for %s into file: %v\n", ea.EaName, err)
77
+
} else {
78
+
fmt.Printf("Extracted EaValue in \"%s\"", ea.EaName)
Copy file name to clipboardExpand all lines: cmd/write_file_ea/write_file_ea.go
+37-5Lines changed: 37 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -15,17 +15,18 @@ import (
15
15
16
16
funcmain() {
17
17
varsrcPath, targetPath, eaNamestring
18
-
varneedEa, removeEabool
18
+
varneedEa, removeEa, stdinbool
19
19
20
20
flag.StringVar(&targetPath, "target-path", "", "path of target file to write EA")
21
21
flag.StringVar(&srcPath, "source-path", "", "path of source file to be used as content for EA")
22
22
flag.StringVar(&eaName, "ea-name", "", "name of the EA")
23
23
24
24
flag.BoolVar(&needEa, "need-ea", false, "set flag if file needs to be interpreted with EA")
25
25
flag.BoolVar(&removeEa, "remove-ea", false, "remove the EA with the given name")
26
+
flag.BoolVar(&stdin, "stdin", false, "use stdin as content for EA")
26
27
27
28
flag.Usage=func() {
28
-
fmt.Fprintf(flag.CommandLine.Output(), "%s writes EA(Extended Attribute) info a file in NTFS(New Technology File System) with the content of a given source file, if the source file is empty the EA with EaName is removed if exists.\nUsage: %s [target path] [source path] [EA name]\n or\n %s -target-path [target path] -source-path [source path] -ea-name [EA name] -need-ea\nTo remove EA with specific name, use: %s -remove-ea [target path] [EA name]\nThis program is supposed to work only in Windows.\n\n", os.Args[0], os.Args[0], os.Args[0], os.Args[0])
29
+
fmt.Fprintf(flag.CommandLine.Output(), "%s writes EA(Extended Attribute) info a file in NTFS(New Technology File System) with the content of a given source file, if the source file is empty the EA with EaName is removed if exists.\nUsage: %s [target path] [source path] [EA name]\n or\n %s -target-path [target path] -source-path [source path] -ea-name [EA name] -need-ea\nWrite EA from stdin: echo \"[content for ea] | %s -stdin -target-path [target path] -ea-name [EA name]\nTo remove EA with specific name, use: %s -remove-ea [target path] [EA name]\n\n", os.Args[0], os.Args[0], os.Args[0], os.Args[0], os.Args[0])
0 commit comments