diff options
Diffstat (limited to 'src/node/ext/byte_buffer.cc')
-rw-r--r-- | src/node/ext/byte_buffer.cc | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/node/ext/byte_buffer.cc b/src/node/ext/byte_buffer.cc index 8e0b6916e9..3479a67702 100644 --- a/src/node/ext/byte_buffer.cc +++ b/src/node/ext/byte_buffer.cc @@ -72,17 +72,13 @@ Local<Value> ByteBufferToBuffer(grpc_byte_buffer *buffer) { if (buffer == NULL) { return scope.Escape(Nan::Null()); } - size_t length = grpc_byte_buffer_length(buffer); - char *result = new char[length]; - size_t offset = 0; grpc_byte_buffer_reader reader; grpc_byte_buffer_reader_init(&reader, buffer); - gpr_slice next; - while (grpc_byte_buffer_reader_next(&reader, &next) != 0) { - memcpy(result + offset, GPR_SLICE_START_PTR(next), GPR_SLICE_LENGTH(next)); - offset += GPR_SLICE_LENGTH(next); - gpr_slice_unref(next); - } + gpr_slice slice = grpc_byte_buffer_reader_readall(&reader); + size_t length = GPR_SLICE_LENGTH(slice); + char *result = new char[length]; + memcpy(result, GPR_SLICE_START_PTR(slice), length); + gpr_slice_unref(slice); return scope.Escape(MakeFastBuffer( Nan::NewBuffer(result, length, delete_buffer, NULL).ToLocalChecked())); } |