buffer-entry.js 804 B

123456789101112131415161718192021222324252627282930
  1. // just like the Entry class, but it buffers the contents
  2. //
  3. // XXX It would be good to set a maximum BufferEntry filesize,
  4. // since it eats up memory. In normal operation,
  5. // these are only for long filenames or link names, which are
  6. // rarely very big.
  7. module.exports = BufferEntry
  8. var inherits = require("inherits")
  9. , Entry = require("./entry.js")
  10. function BufferEntry () {
  11. Entry.apply(this, arguments)
  12. this._buffer = new Buffer(this.props.size)
  13. this._offset = 0
  14. this.body = ""
  15. this.on("end", function () {
  16. this.body = this._buffer.toString().slice(0, -1)
  17. })
  18. }
  19. inherits(BufferEntry, Entry)
  20. // collect the bytes as they come in.
  21. BufferEntry.prototype.write = function (c) {
  22. c.copy(this._buffer, this._offset)
  23. this._offset += c.length
  24. Entry.prototype.write.call(this, c)
  25. }