File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,12 @@ internals.lengthCompare = function (a, b) {
115
115
} ;
116
116
117
117
118
+ internals . purdy . prototype . Uint8Array = function ( buffer ) {
119
+
120
+ return '<Buffer ' + buffer . slice ( 0 , 25 ) . toString ( 'utf8' ) + ' ... >' ;
121
+ } ;
122
+
123
+
118
124
internals . purdy . prototype . tidyPath = function ( path ) {
119
125
120
126
return this . colorize ( path . slice ( 1 , path . size ) , 'path' ) ;
Original file line number Diff line number Diff line change @@ -61,6 +61,29 @@ describe('Purdy', () => {
61
61
} ) ;
62
62
} ) ;
63
63
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 ( / < B u f f e r s o m e l o n g e r s t r i n g h e r e 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 ( / d a t a .* B u f f e r / ) ;
82
+ done ( ) ;
83
+ } ) ;
84
+ } ) ;
85
+ } ) ;
86
+
64
87
it ( 'should print an object without a constructor' , ( done ) => {
65
88
66
89
const out = Purdy . stringify ( { constructor : null } ) ;
You can’t perform that action at this time.
0 commit comments