Handle zero-length Buffers in Node.js v13.2.0+

These now use nullptr internally - see
https://github.com/nodejs/node/pull/30339
This commit is contained in:
Lovell Fuller 2019-11-28 21:20:32 +00:00
parent bb15cd9067
commit 400ef71b6f
3 changed files with 6 additions and 1 deletions

View File

@ -6,6 +6,8 @@ Requires libvips v8.8.1.
#### v0.23.4 - TBD
* Handle zero-length Buffer objects when using Node.js v13.2.0+.
* Improve thread safety by using copy-on-write when updating metadata.
[#1986](https://github.com/lovell/sharp/issues/1986)

View File

@ -58,6 +58,7 @@ namespace sharp {
v8::Local<v8::Object> buffer = AttrAs<v8::Object>(input, "buffer");
descriptor->bufferLength = node::Buffer::Length(buffer);
descriptor->buffer = node::Buffer::Data(buffer);
descriptor->isBuffer = TRUE;
buffersToPersist.push_back(buffer);
}
descriptor->failOnError = AttrTo<bool>(input, "failOnError");
@ -246,7 +247,7 @@ namespace sharp {
std::tuple<VImage, ImageType> OpenInput(InputDescriptor *descriptor, VipsAccess accessMethod) {
VImage image;
ImageType imageType;
if (descriptor->buffer != nullptr) {
if (descriptor->isBuffer) {
if (descriptor->rawChannels > 0) {
// Raw, uncompressed pixel data
image = VImage::new_from_memory(descriptor->buffer, descriptor->bufferLength,

View File

@ -49,6 +49,7 @@ namespace sharp {
char *buffer;
bool failOnError;
size_t bufferLength;
bool isBuffer;
double density;
int rawChannels;
int rawWidth;
@ -64,6 +65,7 @@ namespace sharp {
buffer(nullptr),
failOnError(TRUE),
bufferLength(0),
isBuffer(FALSE),
density(72.0),
rawChannels(0),
rawWidth(0),