public
Created

Stream.readlnBoundary (work-around for no unbounded memory stream)

  • Download Gist
example.js
JavaScript
1 2
// Example use:
var header_line = this.readlnBoundary( '\u000d\u000a' );
stream_readlnboundary.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
system.tmpfile = function() {
var d = new Date();
var r = String(Math.random()).replace(/\./,'');;
var n = '/tmp/tmp-' + r + '-' + d.valueOf();
var s = new Stream( n, 'w+' );
return s;
}
 
Stream.prototype.readBinBoundary = function( boundary ) {
var tmp_file = system.tmpfile();
var tmp_name = tmp_file.name;
this.readUntilBytes( boundary, tmp_file );
tmp_file.close();
return (tmp_name);
}
 
Stream.prototype.readlnBoundary = function( boundary ) {
var tmp_name = this.readBinBoundary( boundary );
var ln_stream = new Stream( tmp_name );
var ln_text = ln_stream.readFile();
ln_stream.close();
system.remove( tmp_name );
return ln_text;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.