Skip to content

Commit b0bfb84

Browse files
committed
expand buffer by multiple of mapi blk size chunks
1 parent f2ebf41 commit b0bfb84

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/mapi.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,9 @@ class Response {
376376
if (!this.complete()) {
377377
// check if out of space
378378
if (this.buff.length - this.offset < data.length) {
379-
const bytes = this.expand(MAPI_BLOCK_SIZE);
380-
console.log(`expanding by ${bytes} bytes!`);
379+
const nsize = (data.length + MAPI_BLOCK_SIZE)&~MAPI_BLOCK_SIZE;
380+
const bytes = this.expand(nsize);
381+
//console.log(`expanding by ${bytes} bytes!`);
381382
}
382383

383384
if (segment === undefined || (segment && segment.isFull())) {
@@ -473,7 +474,7 @@ class Response {
473474
this.offset -= offset;
474475
}
475476
}
476-
const buff = Buffer.allocUnsafe(this.buff.length + byteCount).fill(0);
477+
const buff = Buffer.allocUnsafe(this.buff.length + byteCount);
477478
const bytesCopied = this.buff.copy(buff);
478479
this.buff = buff;
479480
// should be byteCount
@@ -716,7 +717,7 @@ class MapiConnection extends EventEmitter {
716717
socket.addListener("error", this.handleSocketError.bind(this));
717718
socket.addListener("timeout", this.handleTimeout.bind(this));
718719
socket.addListener("close", () => {
719-
console.log("socket close event");
720+
//console.log("socket close event");
720721
this.emit("end");
721722
});
722723
return socket;
@@ -916,8 +917,8 @@ class MapiConnection extends EventEmitter {
916917
if (resp.complete()) this.handleResponse(resp);
917918
bytesLeftOver = data.length - offset;
918919
if (bytesLeftOver) {
919-
const msg = `some ${bytesLeftOver} bytes left over!`;
920-
console.warn(msg);
920+
//const msg = `some ${bytesLeftOver} bytes left over!`;
921+
//console.warn(msg);
921922
this.recv(data.subarray(offset));
922923
}
923924
}
@@ -939,7 +940,7 @@ class MapiConnection extends EventEmitter {
939940
return;
940941
}
941942
if (resp.isPrompt()) {
942-
console.log("login OK");
943+
//console.log("login OK");
943944
this.state = MAPI_STATE.READY;
944945
this.emit("ready", this.state);
945946
return;
@@ -948,7 +949,7 @@ class MapiConnection extends EventEmitter {
948949
}
949950

950951
if (resp.isFileTransfer()) {
951-
console.log("file transfer");
952+
//console.log("file transfer");
952953
let fhandler: any;
953954
const msg = resp.toString(MSG_FILETRANS.length).trim();
954955
let mode: string, offset: string, file: string;

test/exec-queries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import assert from "assert";
22
import Connection from "../src/connection";
33

4-
describe("Exec queres", function () {
4+
describe("Exec queries", function () {
55
let conn: Connection;
66
beforeEach(function () {
77
conn = new Connection({ database: "test" });

0 commit comments

Comments
 (0)