Unbounded memory stream?

21 views
Skip to first unread message

Mike Acton

unread,
Feb 12, 2012, 12:51:10 AM2/12/12
to js...@googlegroups.com
Is there an undocumented way to create an unbounded memory stream? 

Documentation states that fifo:// stream requires size. 
  • There's no (optional?) realloc when pre-allocation limit is reached?
  • There's no callback if I hit the end, so no way to realloc in the client code.
  • If it's used as a destination stream in a Stream.readUntil, it's not clear what happens when the limit is reached.
Use case:
Work-around:
  • Create temporary file stream (see also: Other request for mkstemp)
  • Use temp stream as destination if Stream.readUntilBytes
  • Read back in from temporary file stream into return var.
  • Delete temporary file stream (see also: remove() is not in global)
This is obviously not ideal or fast.


e.g. header_line = this.readlnBoundary( '\u000d\u000a' ); 

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;
} 

Anyone have another suggestion for a less roundabout solution?

Mike.





Shanti Rao

unread,
Feb 12, 2012, 1:03:13 PM2/12/12
to js...@googlegroups.com
M = new Stream();

Is an unbounded auto-extending memory stream.

Mike Acton

unread,
Feb 12, 2012, 2:36:01 PM2/12/12
to js...@googlegroups.com
Ha! Thanks. That should simplify things a bit. :)
Reply all
Reply to author
Forward
0 new messages