-class UploadStream:
- """Identifier for streams that are uploaded to peers."""
-
-class FileUploaderStream(stream.FileStream, UploadStream):
- """Modified to make it suitable for streaming to peers.
-
- Streams the file in small chunks to make it easier to throttle the
- streaming to peers.
-
- @ivar CHUNK_SIZE: the size of chunks of data to send at a time
- """
-
- CHUNK_SIZE = 4*1024
-
- def read(self, sendfile=False):
- if self.f is None:
- return None
-
- length = self.length
- if length == 0:
- self.f = None
- return None
-
- # Remove the SendFileBuffer and mmap use, just use string reads and writes
-
- readSize = min(length, self.CHUNK_SIZE)
-
- self.f.seek(self.start)
- b = self.f.read(readSize)
- bytesRead = len(b)
- if not bytesRead:
- raise RuntimeError("Ran out of data reading file %r, expected %d more bytes" % (self.f, length))
- else:
- self.length -= bytesRead
- self.start += bytesRead
- return b
-
-class PiecesUploaderStream(stream.MemoryStream, UploadStream):
- """Modified to identify it for streaming to peers."""
-