buf.js 773 B

12345678910111213141516171819202122232425262728293031323334
  1. var path = require('path');
  2. var test = require('tape');
  3. var Buffer = require('safe-buffer').Buffer;
  4. var Writable = require('../').Writable;
  5. var inherits = require('inherits');
  6. inherits(TestWritable, Writable);
  7. function TestWritable(opt) {
  8. if (!(this instanceof TestWritable))
  9. return new TestWritable(opt);
  10. Writable.call(this, opt);
  11. this._written = [];
  12. }
  13. TestWritable.prototype._write = function(chunk, encoding, cb) {
  14. this._written.push(chunk);
  15. cb();
  16. };
  17. var buf = Buffer.from([ 88 ]);
  18. test('.writable writing ArrayBuffer', function(t) {
  19. var writable = new TestWritable();
  20. writable.write(buf);
  21. writable.end();
  22. t.equal(writable._written.length, 1);
  23. t.equal(writable._written[0].toString(), 'X')
  24. t.end()
  25. });