From 3a984edb02143f478452e63b2b1437a0967f522d Mon Sep 17 00:00:00 2001 From: Matze2010 Date: Wed, 12 Feb 2014 17:54:36 +0100 Subject: [PATCH] Possibility to set filename of literal data packet (tag 11) The filename of the literal data packet was hardcoded to msg.txt. Now one has the possibility to manually set the filename of the literal data packet. --- src/packet/literal.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/packet/literal.js b/src/packet/literal.js index 1a58d680..16287be7 100644 --- a/src/packet/literal.js +++ b/src/packet/literal.js @@ -38,6 +38,7 @@ function Literal() { this.format = 'utf8'; // default format for literal data packets this.data = ''; // literal data representation as native JavaScript string or bytes this.date = new Date(); + this.filename = 'msg.txt'; } /** @@ -84,6 +85,24 @@ Literal.prototype.getBytes = function () { }; +/** + * Sets the filename of the literal packet data + * @param {String} filename Any native javascript string + */ +Literal.prototype.setFilename = function (filename) { + this.filename = filename; +}; + + +/** + * Get the filename of the literal packet data + * @returns {String} filename + */ +Literal.prototype.getFilename = function() { + return this.filename; +}; + + /** * Parsing function for a literal data packet (tag 11). * @@ -117,7 +136,7 @@ Literal.prototype.read = function (bytes) { * @return {String} string-representation of the packet */ Literal.prototype.write = function () { - var filename = util.encode_utf8("msg.txt"); + var filename = util.encode_utf8(this.filename); var data = this.getBytes();