@@ -23,15 +23,26 @@ var constants = jsFS.Get("constants")
23
23
var uint8Array = js .Global ().Get ("Uint8Array" )
24
24
25
25
var (
26
- nodeWRONLY = constants .Get ("O_WRONLY" ).Int ()
27
- nodeRDWR = constants .Get ("O_RDWR" ).Int ()
28
- nodeCREATE = constants .Get ("O_CREAT" ).Int ()
29
- nodeTRUNC = constants .Get ("O_TRUNC" ).Int ()
30
- nodeAPPEND = constants .Get ("O_APPEND" ).Int ()
31
- nodeEXCL = constants .Get ("O_EXCL" ).Int ()
32
- nodeDIRECTORY = constants .Get ("O_DIRECTORY" ).Int ()
26
+ nodeWRONLY = constants .Get ("O_WRONLY" ).Int ()
27
+ nodeRDWR = constants .Get ("O_RDWR" ).Int ()
28
+ nodeCREATE = constants .Get ("O_CREAT" ).Int ()
29
+ nodeTRUNC = constants .Get ("O_TRUNC" ).Int ()
30
+ nodeAPPEND = constants .Get ("O_APPEND" ).Int ()
31
+ nodeEXCL = constants .Get ("O_EXCL" ).Int ()
32
+
33
+ // NodeJS on Windows does not support O_DIRECTORY, so we default
34
+ // to -1 and assign it in init if available.
35
+ // See https://nodejs.org/docs/latest/api/fs.html#file-open-constants.
36
+ nodeDIRECTORY = - 1
33
37
)
34
38
39
+ func init () {
40
+ oDir := constants .Get ("O_DIRECTORY" )
41
+ if ! oDir .IsUndefined () {
42
+ nodeDIRECTORY = oDir .Int ()
43
+ }
44
+ }
45
+
35
46
type jsFile struct {
36
47
path string
37
48
entries []string
@@ -85,7 +96,11 @@ func Open(path string, openmode int, perm uint32) (int, error) {
85
96
return 0 , errors .New ("syscall.Open: O_SYNC is not supported by js/wasm" )
86
97
}
87
98
if openmode & O_DIRECTORY != 0 {
88
- flags |= nodeDIRECTORY
99
+ if nodeDIRECTORY != - 1 {
100
+ flags |= nodeDIRECTORY
101
+ } else {
102
+ return 0 , errors .New ("syscall.Open: O_DIRECTORY is not supported on Windows" )
103
+ }
89
104
}
90
105
91
106
jsFD , err := fsCall ("open" , path , flags , perm )
0 commit comments