Giter VIP home page Giter VIP logo

Comments (2)

nickdesaulniers avatar nickdesaulniers commented on August 28, 2024

as noted in the readme of https://www.npmjs.com/package/buffer-factory, we can't just use Buffer.from if we want to keep our tests green for pre-Node v4. So I think we should add buffer-factory as a devDependency then change the tests to use them.

Locally, I have:

diff --git a/perf/common.js b/perf/common.js
index d08d6f5..00867bc 100644
--- a/perf/common.js
+++ b/perf/common.js
@@ -4,7 +4,7 @@ exports.createMsg = function(msgType, sz) {
   var buf;
   switch (msgType) {
     case '--buffer':
-      buf = new Buffer(sz);
+      buf = Buffer.alloc(sz);
       buf.fill('o');
       break;
     case '--string':
diff --git a/test/send.js b/test/send.js
index c5993e8..2b1bcd9 100644
--- a/test/send.js
+++ b/test/send.js
@@ -54,7 +54,7 @@ test('send can take a buffer', function (t) {
   var pub = nano.socket('pub');
   var sub = nano.socket('sub');
   var addr = 'inproc://some_address';
-  var msg = new Buffer('hello');
+  var msg = Buffer.from('hello');
 
   pub.bind(addr);
   sub.connect(addr);
@@ -85,7 +85,7 @@ test('should not null terminate when sending strings', function (t) {
     if (buf[buf.length - 1] === 0) {
       t.fail();
     }
-    t.equal(buf.equals(new Buffer(msg)), true);
+    t.equal(buf.equals(Buffer.from(msg)), true);
     t.equal(buf.length, msg.length);
     pub.close();
     sub.close();
diff --git a/test/transform.js b/test/transform.js
index 01fdbb4..c3e0acc 100644
--- a/test/transform.js
+++ b/test/transform.js
@@ -5,12 +5,12 @@ var nano = require('../');
 var test = require('tape');
 
 nano.Socket.prototype.transform = function (buf) {
-    if (!Buffer.isBuffer(buf)) buf = new Buffer(buf);
-    return Buffer.concat([new Buffer([0x00]), buf]);
+    if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
+    return Buffer.concat([Buffer.from([0x00]), buf]);
 }
 
 nano.Socket.prototype.restore = function (buf) {
-    return Buffer.concat([new Buffer([0xFF]), buf]);
+    return Buffer.concat([Buffer.from([0xFF]), buf]);
 }
 
 test('inproc socket pub sub', function (t) {

but I think I would prefer the added dev dependency.

from node-nanomsg.

nickdesaulniers avatar nickdesaulniers commented on August 28, 2024

nvm, buffer-factory has a clear bug in it. prefer: https://www.npmjs.com/package/buffer-from

from node-nanomsg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.