Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed blob allocation and warning
Browse files Browse the repository at this point in the history
kelvinhammond committed Dec 9, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 9f14049 commit 3d0956c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/blob.h
Original file line number Diff line number Diff line change
@@ -29,17 +29,20 @@ class Blob : public Napi::ObjectWrap<Blob> {
if (info[0].IsArrayBuffer()) { // handle ArrayBuffer
auto buf = info[0].As<Napi::ArrayBuffer>();
size = buf.ByteLength();
data = std::shared_ptr<char>(new char[size]);
data = std::shared_ptr<char>(new char[size],
std::default_delete<char[]>());
memcpy(data.get(), buf.Data(), size);
} else if (info[0].IsBuffer()) { // handle Buffer
auto buf = info[0].As<Napi::Buffer<char>>();
size = buf.Length();
data = std::shared_ptr<char>(new char[size]);
data = std::shared_ptr<char>(new char[size],
std::default_delete<char[]>());
memcpy(data.get(), buf.Data(), size);
} else { // all others toString()
auto str = info[0].ToString().Utf8Value(); // coerce to string
size = str.size();
data = std::shared_ptr<char>(new char[size]);
data = std::shared_ptr<char>(new char[size],
std::default_delete<char[]>());
memcpy(data.get(), str.c_str(), size);
}

0 comments on commit 3d0956c

Please sign in to comment.