You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.6 KiB

  1. var assert = require('assert');
  2. var Dicer = require('..'),
  3. boundary = '-----------------------------168072824752491622650073',
  4. d = new Dicer({ boundary: boundary }),
  5. mb = 100,
  6. buffer = createMultipartBuffer(boundary, mb * 1024 * 1024),
  7. callbacks =
  8. { partBegin: -1,
  9. partEnd: -1,
  10. headerField: -1,
  11. headerValue: -1,
  12. partData: -1,
  13. end: -1,
  14. };
  15. d.on('part', function(p) {
  16. callbacks.partBegin++;
  17. p.on('header', function(header) {
  18. /*for (var h in header)
  19. console.log('Part header: k: ' + inspect(h) + ', v: ' + inspect(header[h]));*/
  20. });
  21. p.on('data', function(data) {
  22. callbacks.partData++;
  23. //console.log('Part data: ' + inspect(data.toString()));
  24. });
  25. p.on('end', function() {
  26. //console.log('End of part\n');
  27. callbacks.partEnd++;
  28. });
  29. });
  30. d.on('end', function() {
  31. //console.log('End of parts');
  32. callbacks.end++;
  33. });
  34. var start = +new Date(),
  35. nparsed = d.write(buffer),
  36. duration = +new Date - start,
  37. mbPerSec = (mb / (duration / 1000)).toFixed(2);
  38. console.log(mbPerSec+' mb/sec');
  39. //assert.equal(nparsed, buffer.length);
  40. function createMultipartBuffer(boundary, size) {
  41. var head =
  42. '--'+boundary+'\r\n'
  43. + 'content-disposition: form-data; name="field1"\r\n'
  44. + '\r\n'
  45. , tail = '\r\n--'+boundary+'--\r\n'
  46. , buffer = Buffer.allocUnsafe(size);
  47. buffer.write(head, 'ascii', 0);
  48. buffer.write(tail, 'ascii', buffer.length - tail.length);
  49. return buffer;
  50. }
  51. process.on('exit', function() {
  52. /*for (var k in callbacks) {
  53. assert.equal(0, callbacks[k], k+' count off by '+callbacks[k]);
  54. }*/
  55. });