@@ -789,7 +789,7 @@ function readvSync(fd, buffers, position) {
789
789
* Writes `buffer` to the specified `fd` (file descriptor).
790
790
* @param {number } fd
791
791
* @param {Buffer | TypedArray | DataView | string | object } buffer
792
- * @param {number } [offset ]
792
+ * @param {number | object } [offsetOrOptions ]
793
793
* @param {number } [length]
794
794
* @param {number } [position]
795
795
* @param {(
@@ -799,16 +799,26 @@ function readvSync(fd, buffers, position) {
799
799
* ) => any} callback
800
800
* @returns {void }
801
801
*/
802
- function write ( fd , buffer , offset , length , position , callback ) {
802
+ function write ( fd , buffer , offsetOrOptions , length , position , callback ) {
803
803
function wrapper ( err , written ) {
804
804
// Retain a reference to buffer so that it can't be GC'ed too soon.
805
805
callback ( err , written || 0 , buffer ) ;
806
806
}
807
807
808
808
fd = getValidatedFd ( fd ) ;
809
809
810
+ let offset = offsetOrOptions ;
810
811
if ( isArrayBufferView ( buffer ) ) {
811
812
callback = maybeCallback ( callback || position || length || offset ) ;
813
+
814
+ if ( typeof offset === 'object' ) {
815
+ ( {
816
+ offset = 0 ,
817
+ length = buffer . byteLength - offset ,
818
+ position = null
819
+ } = offsetOrOptions ?? ObjectCreate ( null ) ) ;
820
+ }
821
+
812
822
if ( offset == null || typeof offset === 'function' ) {
813
823
offset = 0 ;
814
824
} else {
@@ -867,15 +877,14 @@ function writeSync(fd, buffer, offsetOrOptions, length, position) {
867
877
let result ;
868
878
869
879
let offset = offsetOrOptions ;
870
- if ( typeof offset === 'object' && offset !== null ) {
871
- ( {
872
- offset = 0 ,
873
- length = buffer . byteLength - offset ,
874
- position = null
875
- } = offsetOrOptions ) ;
876
- }
877
-
878
880
if ( isArrayBufferView ( buffer ) ) {
881
+ if ( typeof offset === 'object' ) {
882
+ ( {
883
+ offset = 0 ,
884
+ length = buffer . byteLength - offset ,
885
+ position = null
886
+ } = offsetOrOptions ?? ObjectCreate ( null ) ) ;
887
+ }
879
888
if ( position === undefined )
880
889
position = null ;
881
890
if ( offset == null ) {
0 commit comments