Closed xxaier closed 1 year ago
Hi, following code works for binaries:
const bin = await fs.readFile("./binary-example.png");
console.log("binary file size: %s", bin.length);
r.rawCall(["set", "binary", bin.toString("binary")], (err, resp) => {
console.log("SET via rawCall command returns err: %s, resp: %s", err, resp);
});
r.rawCall(["get", "binary"], async (err, resp) => {
console.log(
"GET via rawCall command returns err: %s, resp: %s",
err,
resp.length
);
const b = Buffer.from(resp, "binary");
console.log("binary file size: %s", b.length);
await fs.writeFile("./binary-example-out.png", b);
r.end();
});
The trick is bin.toString("binary")
and then Buffer.from(resp, "binary")
Full example: example-binary.js
as title