2525
2626#{ RO Streams
2727
28- class NullStream (object ):
29- """A stream that does nothing but providing a stream interface.
30- Use it like /dev/null"""
31- __slots__ = tuple ()
32-
33- def read (self , size = 0 ):
34- return ''
35-
36- def close (self ):
37- pass
38-
39- def write (self , data ):
40- return len (data )
41-
42-
4328class DecompressMemMapReader (LazyMixin ):
4429 """Reads data in chunks from a memory map and decompresses it. The client sees
4530 only the uncompressed data, respective file-like read calls are handling on-demand
@@ -113,6 +98,8 @@ def _parse_header_info(self):
11398
11499 return type , size
115100
101+ #{ Interface
102+
116103 @classmethod
117104 def new (self , m , close_on_deletion = False ):
118105 """Create a new DecompressMemMapReader instance for acting as a read-only stream
@@ -125,6 +112,10 @@ def new(self, m, close_on_deletion=False):
125112 type , size = inst ._parse_header_info ()
126113 return type , size , inst
127114
115+ def data (self ):
116+ """:return: random access compatible data we are working on"""
117+ return self ._m
118+
128119 def compressed_bytes_read (self ):
129120 """:return: number of compressed bytes read. This includes the bytes it
130121 took to decompress the header ( if there was one )"""
@@ -171,6 +162,8 @@ def compressed_bytes_read(self):
171162 # from the count already
172163 return self ._cbr
173164
165+ #} END interface
166+
174167 def seek (self , offset , whence = os .SEEK_SET ):
175168 """Allows to reset the stream to restart reading
176169 :raise ValueError: If offset and whence are not 0"""
@@ -567,4 +560,32 @@ def close(self):
567560
568561 #} END stream interface
569562
563+ class FDStream (object ):
564+ """Simple wrapper around a file descriptor"""
565+ __slots__ = "_fd"
566+ def __init__ (self , fd ):
567+ self ._fd = fd
568+
569+ def write (self , data ):
570+ return write (self ._fd , data )
571+
572+ def close (self ):
573+ close (self ._fd )
574+
575+
576+
577+ class NullStream (object ):
578+ """A stream that does nothing but providing a stream interface.
579+ Use it like /dev/null"""
580+ __slots__ = tuple ()
581+
582+ def read (self , size = 0 ):
583+ return ''
584+
585+ def close (self ):
586+ pass
587+
588+ def write (self , data ):
589+ return len (data )
590+
570591#} END W streams
0 commit comments