Initial commit
[yaffs-website] / node_modules / tar / lib / buffer-entry.js
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
8 module.exports = BufferEntry
9
10 var inherits = require("inherits")
11   , Entry = require("./entry.js")
12
13 function BufferEntry () {
14   Entry.apply(this, arguments)
15   this._buffer = new Buffer(this.props.size)
16   this._offset = 0
17   this.body = ""
18   this.on("end", function () {
19     this.body = this._buffer.toString().slice(0, -1)
20   })
21 }
22
23 inherits(BufferEntry, Entry)
24
25 // collect the bytes as they come in.
26 BufferEntry.prototype.write = function (c) {
27   c.copy(this._buffer, this._offset)
28   this._offset += c.length
29   Entry.prototype.write.call(this, c)
30 }