def read(self, n=-1): """Reads ``n`` bytes from the file. If ``n`` is not specified or is ``-1`` the whole file content is read in memory and returned """ if self._data is _marker: file_id = DBSession.merge(self).file_id self._data = DBSession.query(DBStoredFile.data).filter_by(file_id=file_id).scalar() if n == -1: result = self._data[self._cursor :] else: result = self._data[self._cursor : self._cursor + n] self._cursor += len(result) return result
def read(self, n=-1): """Reads ``n`` bytes from the file. If ``n`` is not specified or is ``-1`` the whole file content is read in memory and returned """ if self._data is _marker: file_id = DBSession.merge(self).file_id self._data = DBSession.query(DBStoredFile.data).\ filter_by(file_id=file_id).scalar() if n == -1: result = self._data[self._cursor:] else: result = self._data[self._cursor:self._cursor + n] self._cursor += len(result) return result