Skip to content

Commit 7a7dcb9

Browse files
authored
Merge pull request #5 from roycwc/main
Error Writing file with file size >2GB
2 parents 0ac298a + 4a25468 commit 7a7dcb9

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

websocket-sftp/lib/sftp-packet.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,17 @@ export class SftpPacketReader extends SftpPacket {
161161
}
162162

163163
readInt64(): number {
164-
const hi = this.readInt32();
165-
const lo = this.readUInt32();
166-
167-
const value = hi * 0x100000000 + lo;
168-
return value;
164+
this.check(8);
165+
const value = this.buffer.readBigInt64BE(this.position);
166+
this.position += 8;
167+
return Number(value);
169168
}
170169

171170
readUInt64(): number {
172-
const hi = this.readUInt32();
173-
const lo = this.readUInt32();
174-
const value = hi * 0x100000000 + lo;
175-
return value;
171+
this.check(8);
172+
const value = this.buffer.readBigUint64BE(this.position);
173+
this.position += 8;
174+
return Number(value);
176175
}
177176

178177
readString(): string {
@@ -271,17 +270,15 @@ export class SftpPacketWriter extends SftpPacket {
271270
}
272271

273272
writeInt64(value: number): void {
274-
const hi = (value / 0x100000000) | 0;
275-
const lo = (value & 0xffffffff) | 0;
276-
this.writeInt32(hi);
277-
this.writeInt32(lo);
273+
this.check(8);
274+
this.buffer.writeBigInt64BE(BigInt(value), this.position);
275+
this.position += 8;
278276
}
279277

280278
writeUInt64(value: number): void {
281-
const hi = (value / 0x100000000) | 0;
282-
const lo = (value & 0xffffffff) | 0;
283-
this.writeUInt32(hi);
284-
this.writeUInt32(lo);
279+
this.check(8);
280+
this.buffer.writeBigUInt64BE(BigInt(value), this.position);
281+
this.position += 8;
285282
}
286283

287284
writeString(value: string): void {

0 commit comments

Comments
 (0)