mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Streaming mode for downloading all rows as a CSV (#315)
* table.csv?_stream=1 to download all rows - refs #266 This option causes Datasette to serve ALL rows in the table, by internally following the _next= pagination links and serving everything out as a stream. Also added new config option, allow_csv_stream, which can be used to disable this feature. * New config option max_csv_mb limiting size of CSV export
This commit is contained in:
parent
0d7ba1ba67
commit
fc3660cfad
11 changed files with 142 additions and 24 deletions
|
|
@ -832,3 +832,22 @@ def value_as_boolean(value):
|
|||
|
||||
class ValueAsBooleanError(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
class WriteLimitExceeded(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class LimitedWriter:
|
||||
def __init__(self, writer, limit_mb):
|
||||
self.writer = writer
|
||||
self.limit_bytes = limit_mb * 1024 * 1024
|
||||
self.bytes_count = 0
|
||||
|
||||
def write(self, bytes):
|
||||
self.bytes_count += len(bytes)
|
||||
if self.limit_bytes and (self.bytes_count > self.limit_bytes):
|
||||
raise WriteLimitExceeded("CSV contains more than {} bytes".format(
|
||||
self.limit_bytes
|
||||
))
|
||||
self.writer.write(bytes)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue