@@ -161,10 +161,6 @@ MlNodeDevice.prototype.open = function (name, f, perms, raise_unix) {
161
161
}
162
162
try {
163
163
var fd = this . fs . openSync ( this . nm ( name ) , res , perms ) ;
164
- var isCharacterDevice = this . fs
165
- . lstatSync ( this . nm ( name ) )
166
- . isCharacterDevice ( ) ;
167
- f . isCharacterDevice = isCharacterDevice ;
168
164
return new MlNodeFd ( fd , f ) ;
169
165
} catch ( err ) {
170
166
caml_raise_nodejs_error ( err , raise_unix ) ;
@@ -333,7 +329,10 @@ function MlNodeFd(fd, flags) {
333
329
this . fs = require ( "node:fs" ) ;
334
330
this . fd = fd ;
335
331
this . flags = flags ;
336
- this . offset = this . flags . append ? this . length ( ) : 0 ;
332
+ var stats = this . fs . fstatSync ( fd ) ;
333
+ flags . noSeek =
334
+ stats . isCharacterDevice ( ) || stats . isFIFO ( ) || stats . isSocket ( ) ;
335
+ this . offset = this . flags . append ? stats . size : 0 ;
337
336
this . seeked = false ;
338
337
}
339
338
MlNodeFd . prototype = new MlFile ( ) ;
@@ -356,7 +355,7 @@ MlNodeFd.prototype.length = function () {
356
355
} ;
357
356
MlNodeFd . prototype . write = function ( buf , buf_offset , len , raise_unix ) {
358
357
try {
359
- if ( this . flags . isCharacterDevice || ! this . seeked )
358
+ if ( this . flags . noSeek || ! this . seeked )
360
359
var written = this . fs . writeSync ( this . fd , buf , buf_offset , len ) ;
361
360
else
362
361
var written = this . fs . writeSync (
@@ -374,7 +373,7 @@ MlNodeFd.prototype.write = function (buf, buf_offset, len, raise_unix) {
374
373
} ;
375
374
MlNodeFd . prototype . read = function ( a , buf_offset , len , raise_unix ) {
376
375
try {
377
- if ( this . flags . isCharacterDevice || ! this . seeked )
376
+ if ( this . flags . noSeek || ! this . seeked )
378
377
var read = this . fs . readSync ( this . fd , a , buf_offset , len ) ;
379
378
else var read = this . fs . readSync ( this . fd , a , buf_offset , len , this . offset ) ;
380
379
this . offset += read ;
@@ -384,7 +383,7 @@ MlNodeFd.prototype.read = function (a, buf_offset, len, raise_unix) {
384
383
}
385
384
} ;
386
385
MlNodeFd . prototype . seek = function ( offset , whence , raise_unix ) {
387
- if ( this . flags . isCharacterDevice )
386
+ if ( this . flags . noSeek )
388
387
caml_raise_system_error ( raise_unix , "ESPIPE" , "lseek" , "illegal seek" ) ;
389
388
switch ( whence ) {
390
389
case 0 :
0 commit comments