Skip to content

Commit 47b9665

Browse files
committed
handle buffers
1 parent abaca8c commit 47b9665

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ internals.lengthCompare = function (a, b) {
115115
};
116116

117117

118+
internals.purdy.prototype.Uint8Array = function (buffer) {
119+
120+
return '<Buffer ' + buffer.slice(0,25).toString('utf8') + ' ... >';
121+
};
122+
123+
118124
internals.purdy.prototype.tidyPath = function (path) {
119125

120126
return this.colorize(path.slice(1, path.size), 'path');

test/purdy.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,29 @@ describe('Purdy', () => {
6161
});
6262
});
6363

64+
describe('buffers', () => {
65+
66+
it('should print as string if detected', (done) => {
67+
68+
const buffer = new Buffer('some longer string here that we dont actually want to print. maybe.');
69+
const out = Purdy.stringify({ buffer });
70+
expect(out).to.match(/<Buffer some longer string here t ... >/);
71+
72+
done();
73+
});
74+
75+
it('should print binary', (done) => {
76+
77+
const fs = require('fs');
78+
fs.readFile('/bin/sh', (err, data) => {
79+
80+
const out = Purdy.stringify({ data });
81+
expect(out).to.match(/data.*Buffer/);
82+
done();
83+
});
84+
});
85+
});
86+
6487
it('should print an object without a constructor', (done) => {
6588

6689
const out = Purdy.stringify({ constructor: null });

0 commit comments

Comments
 (0)