@@ -789,26 +789,38 @@ 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]
793
- * @param {number } [length]
794
- * @param {number } [position]
792
+ * @param {{
793
+ * offset?: number;
794
+ * length?: number;
795
+ * position?: number;
796
+ * }} [offsetOrOptions]
795
797
* @param {(
796
798
* err?: Error,
797
799
* bytesWritten?: number;
798
800
* buffer?: Buffer | TypedArray | DataView
799
801
* ) => any} callback
800
802
* @returns {void }
801
803
*/
802
- function write ( fd , buffer , offset , length , position , callback ) {
804
+ function write ( fd , buffer , offsetOrOptions , length , position , callback ) {
803
805
function wrapper ( err , written ) {
804
806
// Retain a reference to buffer so that it can't be GC'ed too soon.
805
807
callback ( err , written || 0 , buffer ) ;
806
808
}
807
809
808
810
fd = getValidatedFd ( fd ) ;
809
811
812
+ let offset = offsetOrOptions ;
810
813
if ( isArrayBufferView ( buffer ) ) {
811
814
callback = maybeCallback ( callback || position || length || offset ) ;
815
+
816
+ if ( typeof offset === 'object' ) {
817
+ ( {
818
+ offset = 0 ,
819
+ length = buffer . byteLength - offset ,
820
+ position = null
821
+ } = offsetOrOptions ?? ObjectCreate ( null ) ) ;
822
+ }
823
+
812
824
if ( offset == null || typeof offset === 'function' ) {
813
825
offset = 0 ;
814
826
} else {
@@ -867,15 +879,14 @@ function writeSync(fd, buffer, offsetOrOptions, length, position) {
867
879
let result ;
868
880
869
881
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
882
if ( isArrayBufferView ( buffer ) ) {
883
+ if ( typeof offset === 'object' ) {
884
+ ( {
885
+ offset = 0 ,
886
+ length = buffer . byteLength - offset ,
887
+ position = null
888
+ } = offsetOrOptions ?? ObjectCreate ( null ) ) ;
889
+ }
879
890
if ( position === undefined )
880
891
position = null ;
881
892
if ( offset == null ) {
0 commit comments