Skip to main content

Module answer_files_archive

Module answer_files_archive 

Source
Expand description

Streams every file-typed answer of one exercise to a teacher as a zip archive.

Entries are named positionally rather than from file_uploads.name, so that a plugin which anonymizes filenames for its own views cannot leak the real ones through this export.

StructsΒ§

ArchiveSink πŸ”’
Writes the archive bytes into the streaming response channel as they are produced, waiting when the client is not reading them fast enough.

ConstantsΒ§

ARCHIVE_CHANNEL_CAPACITY πŸ”’
How many written chunks may sit between the archive writer and the client before the writer has to wait. The producer reads from the file store as fast as it is served, so without a bound a slow client makes the whole archive accumulate in memory.
MIME_EXTENSIONS πŸ”’
Extensions for the mime types answer files realistically arrive as. Anything else is written without an extension rather than guessed at.

FunctionsΒ§

content_disposition
attachment; filename="..." for an exercise’s archive.
entry_name πŸ”’
<user_id>/<submission_id>/<order_number><ext>, so that the two things a teacher needs to identify an answer come from host-owned data only.
extension_for_mime πŸ”’
The extension to give an archive entry, without the leading dot. None for a mime type we have no confident extension for, including application/octet-stream.
filename_component πŸ”’
Lowercased [a-z0-9-] rendering of user-authored text, for use inside a download filename.
stream_exercise_answer_files
Starts the archive download for one exercise.
write_archive πŸ”’