ferrum-db-client
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -121,3 +121,3 @@ "use strict"; | ||
if (this.pending.has(id)) { | ||
this.pending.get(id)(msgBuffer.slice(4, msgSize)); | ||
this.pending.get(id)(Buffer.from(msgBuffer.slice(4, msgSize))); | ||
this.pending.delete(id); | ||
@@ -488,42 +488,48 @@ } | ||
const len = br.readInt(); | ||
console.log(`Fetched ${len} bytes from DB`); | ||
const result = Buffer.from(br.readBytes(len)); | ||
let decompressed; | ||
let decodedValue; | ||
switch (this.compression) { | ||
case "gzip": | ||
decompressed = await gunzipPromise(result); | ||
break; | ||
default: | ||
decompressed = result; | ||
break; | ||
} | ||
if (this.encoding === "bson") { | ||
if (decompressed.length > bsonBufferSize) { | ||
bson_1.setInternalBufferSize(decompressed.length); | ||
bsonBufferSize = decompressed.length; | ||
console.log(`${key} read ${len} bytes from DB`); | ||
try { | ||
const result = Buffer.from(br.readBytes(len)); | ||
let decompressed; | ||
let decodedValue; | ||
switch (this.compression) { | ||
case "gzip": | ||
decompressed = await gunzipPromise(result); | ||
break; | ||
default: | ||
decompressed = result; | ||
break; | ||
} | ||
decodedValue = bson_1.deserialize(decompressed); | ||
} | ||
else if (this.encoding === "json") { | ||
try { | ||
decodedValue = JSON.parse(decompressed.toString("utf8")); | ||
if (this.encoding === "bson") { | ||
if (decompressed.length > bsonBufferSize) { | ||
bson_1.setInternalBufferSize(decompressed.length); | ||
bsonBufferSize = decompressed.length; | ||
} | ||
decodedValue = bson_1.deserialize(decompressed); | ||
} | ||
catch (e) { | ||
throw new Error(`Failed to decode JSON for key ${key}. ${decompressed.toString("utf8")}`); | ||
else if (this.encoding === "json") { | ||
try { | ||
decodedValue = JSON.parse(decompressed.toString("utf8")); | ||
} | ||
catch (e) { | ||
throw new Error(`Failed to decode JSON for key ${key}. ${decompressed.toString("utf8")}`); | ||
} | ||
} | ||
else if (this.encoding === "ndjson") { | ||
decodedValue = decompressed | ||
.toString("utf8") | ||
.split("\n") | ||
.map((e) => JSON.parse(e)); | ||
} | ||
else if (this.encoding === "string") { | ||
decodedValue = decompressed.toString("utf8"); | ||
} | ||
else { | ||
decodedValue = decompressed; | ||
} | ||
return decodedValue; | ||
} | ||
else if (this.encoding === "ndjson") { | ||
decodedValue = decompressed | ||
.toString("utf8") | ||
.split("\n") | ||
.map((e) => JSON.parse(e)); | ||
catch (e) { | ||
console.error(`Failed to get ${key} from ${this.indexKey}`); | ||
throw e; | ||
} | ||
else if (this.encoding === "string") { | ||
decodedValue = decompressed.toString("utf8"); | ||
} | ||
else { | ||
decodedValue = decompressed; | ||
} | ||
return decodedValue; | ||
} | ||
@@ -530,0 +536,0 @@ } |
{ | ||
"name": "ferrum-db-client", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "dist/client.js", | ||
@@ -5,0 +5,0 @@ "typings": "dist/client.d.ts", |
@@ -157,3 +157,5 @@ import { Socket } from "net"; | ||
if (this.pending.has(id)) { | ||
this.pending.get(id)(msgBuffer.slice(4, msgSize)); | ||
this.pending.get(id)( | ||
Buffer.from(msgBuffer.slice(4, msgSize)) | ||
); | ||
this.pending.delete(id); | ||
@@ -666,44 +668,51 @@ } | ||
const len = br.readInt(); | ||
console.log(`Fetched ${len} bytes from DB`); | ||
const result = Buffer.from(br.readBytes(len)); | ||
let decompressed: Buffer; | ||
let decodedValue: any; | ||
console.log(`${key} read ${len} bytes from DB`); | ||
try { | ||
const result = Buffer.from(br.readBytes(len)); | ||
let decompressed: Buffer; | ||
let decodedValue: any; | ||
switch (this.compression) { | ||
case "gzip": | ||
decompressed = await gunzipPromise(result); | ||
break; | ||
default: | ||
decompressed = result; | ||
break; | ||
} | ||
switch (this.compression) { | ||
case "gzip": | ||
decompressed = await gunzipPromise(result); | ||
break; | ||
default: | ||
decompressed = result; | ||
break; | ||
} | ||
if (this.encoding === "bson") { | ||
if (decompressed.length > bsonBufferSize) { | ||
setInternalBufferSize(decompressed.length); | ||
bsonBufferSize = decompressed.length; | ||
if (this.encoding === "bson") { | ||
if (decompressed.length > bsonBufferSize) { | ||
setInternalBufferSize(decompressed.length); | ||
bsonBufferSize = decompressed.length; | ||
} | ||
decodedValue = deserialize(decompressed); | ||
} else if (this.encoding === "json") { | ||
try { | ||
decodedValue = JSON.parse( | ||
decompressed.toString("utf8") | ||
); | ||
} catch (e) { | ||
throw new Error( | ||
`Failed to decode JSON for key ${key}. ${decompressed.toString( | ||
"utf8" | ||
)}` | ||
); | ||
} | ||
} else if (this.encoding === "ndjson") { | ||
decodedValue = decompressed | ||
.toString("utf8") | ||
.split("\n") | ||
.map((e) => JSON.parse(e)); | ||
} else if (this.encoding === "string") { | ||
decodedValue = decompressed.toString("utf8"); | ||
} else { | ||
decodedValue = decompressed; | ||
} | ||
decodedValue = deserialize(decompressed); | ||
} else if (this.encoding === "json") { | ||
try { | ||
decodedValue = JSON.parse(decompressed.toString("utf8")); | ||
} catch (e) { | ||
throw new Error( | ||
`Failed to decode JSON for key ${key}. ${decompressed.toString( | ||
"utf8" | ||
)}` | ||
); | ||
} | ||
} else if (this.encoding === "ndjson") { | ||
decodedValue = decompressed | ||
.toString("utf8") | ||
.split("\n") | ||
.map((e) => JSON.parse(e)); | ||
} else if (this.encoding === "string") { | ||
decodedValue = decompressed.toString("utf8"); | ||
} else { | ||
decodedValue = decompressed; | ||
return decodedValue; | ||
} catch (e) { | ||
console.error(`Failed to get ${key} from ${this.indexKey}`); | ||
throw e; | ||
} | ||
return decodedValue; | ||
} | ||
@@ -710,0 +719,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
119580
1611