roxen.lists.roxen.general

Subject Author Date
[PATCH 13/17] Add support to StringFile to be used in writing. Stephen R. van den Berg <srb[at]cuci[dot]nl> 20-01-2009
Needed for the gzip-on-the-fly module.
---

 server/base_server/prototypes.pike |   38 +++++++++++++++++++++++++-----------
 1 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/server/base_server/prototypes.pike
b/server/base_server/prototypes.pike
index 8dbd18c..c201d5d 100644
--- a/server/base_server/prototypes.pike
+++ b/server/base_server/prototypes.pike
@@ -89,36 +89,45 @@ class BasicDefvar
 
 
 
-class StringFile( string data, mixed|void _st )
+class StringFile( string|void indata, mixed|void _st )
 {
   int offset;
 
+  array(string) outdata=({});
+
   string _sprintf()
   {
-    return "StringFile("+strlen(data)+","+offset+")";
+    return "StringFile("+sizeof(indata)+","+offset+")";
   }
 
   string read(int nbytes)
   {
-    if(!nbytes)
-    {
-      offset = strlen(data);
-      return data;
-    }
-    string d = data[offset..offset+nbytes-1];
-    offset += strlen(d);
+    if(!stringp(indata))
+      throw( ({ "File not open for read\n", backtrace() }) );
+    string d = nbytes ? indata[offset..offset+nbytes-1] : indata[offset..];
+    offset += sizeof(d);
     return d;
   }
 
   array stat()
   {
     if( _st ) return (array)_st;
-    return ({ 0, strlen(data), time(), time(), time(), 0, 0, 0 });
+    return ({ 0, sizeof(indata), time(), time(), time(), 0, 0, 0 });
   }
 
-  void write(mixed ... args)
+  int write(mixed ... args)
   {
-    throw( ({ "File not open for write\n", backtrace() }) );
+    if(sizeof(args)>1)
+      args = ();
+    else if(arrayp(args[0]))
+      args = args[0];
+    else if(!sizeof(args[0]))
+      return 0;
+    outdata += args;
+    int i=0;
+    foreach(args;;string chunk)
+      i+=sizeof(chunk);
+    return i;
   }
 
   void seek(int to)
@@ -129,6 +138,11 @@ class StringFile( string data, mixed|void _st )
   void set_blocking()
   {
   }
+
+  void close()
+  {
+    return 0;
+  }
 }
 
 class ModuleInfo