1var stream = require('stream'); 2var JsonParse = require('../jsonparse'); 3var test = require('tape'); 4 5test('can handle large tokens without running out of memory', function (t) { 6 var parser = new JsonParse(); 7 var chunkSize = 1024; 8 var chunks = 1024 * 200; // 200mb 9 var quote = Buffer.from ? Buffer.from('"') : new Buffer('"'); 10 t.plan(1); 11 12 parser.onToken = function (type, value) { 13 t.equal(value.length, chunkSize * chunks, 'token should be size of input json'); 14 t.end(); 15 }; 16 17 parser.write(quote); 18 for (var i = 0; i < chunks; ++i) { 19 var buf = Buffer.alloc ? Buffer.alloc(chunkSize) : new Buffer(chunkSize); 20 buf.fill('a'); 21 parser.write(buf); 22 } 23 parser.write(quote); 24}); 25