aboutsummaryrefslogtreecommitdiffstats
path: root/FuseArchive
diff options
context:
space:
mode:
authorSteve Slaven <bpk@hoopajoo.net>2009-11-03 01:03:36 (GMT)
committerSteve Slaven <bpk@hoopajoo.net>2009-11-03 01:03:36 (GMT)
commit3c4a553a245d736622a5ae584e6ddbb0e73b15ff (patch)
tree5ef1620331ad5f50e9c528cd44706e7d235d4654 /FuseArchive
parentcdde104c9c4a70ff801aec269494f1473944b81f (diff)
downloadfusearchive-3c4a553a245d736622a5ae584e6ddbb0e73b15ff.zip
fusearchive-3c4a553a245d736622a5ae584e6ddbb0e73b15ff.tar.gz
fusearchive-3c4a553a245d736622a5ae584e6ddbb0e73b15ff.tar.bz2
Use a cStringBuffer for IO which appears to be faster than using join() for
very large lists
Diffstat (limited to 'FuseArchive')
-rw-r--r--FuseArchive/ChunkBuffer.py3
-rw-r--r--FuseArchive/ChunkBufferStringIO.py30
2 files changed, 32 insertions, 1 deletions
diff --git a/FuseArchive/ChunkBuffer.py b/FuseArchive/ChunkBuffer.py
index 134ce30..8bf3261 100644
--- a/FuseArchive/ChunkBuffer.py
+++ b/FuseArchive/ChunkBuffer.py
@@ -1,7 +1,8 @@
from ChunkBufferMem import ChunkBufferMem
from ChunkBufferFile import ChunkBufferFile
+from ChunkBufferStringIO import ChunkBufferStringIO
# Handle efficient operations on a non-fixed length buffer like appending,
# replacing, reading chunks, etc
-class ChunkBuffer(ChunkBufferMem):
+class ChunkBuffer(ChunkBufferStringIO):
pass
diff --git a/FuseArchive/ChunkBufferStringIO.py b/FuseArchive/ChunkBufferStringIO.py
new file mode 100644
index 0000000..9a27f51
--- /dev/null
+++ b/FuseArchive/ChunkBufferStringIO.py
@@ -0,0 +1,30 @@
+import logging
+from cStringIO import StringIO
+
+# Handle efficient operations on a non-fixed length buffer like appending,
+# replacing, reading chunks, etc
+class ChunkBufferStringIO:
+ def __init__( self, data = '' ):
+ logging.debug( "Creating chunkbuffer: %s" % data )
+ self.io = StringIO();
+ self.len = 0
+ self.append( data )
+
+ def append( self, s ):
+ self.len += len( s )
+ self.io.write( s )
+
+ def replace( self, buf, start, end ):
+ self.io.seek( start )
+ self.io.write( buf[ end - start: ] )
+ self.io.seek( 0, os.SEEK_END )
+
+ def length( self ):
+ return self.len
+
+ def truncate( self, l ):
+ self.len = l
+ self.io.truncate( l )
+
+ def string(self):
+ return self.io.getvalue()