Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
Functions | Variables
coordinator.upload_utils Namespace Reference

Functions

None handle_upload_request (int content_length, str content_boundary, bytes expect_digest, io.BufferedIOBase stream, str file_name)
 

Variables

int READ_CHUNK_SIZE = 4096
 

Function Documentation

◆ handle_upload_request()

None coordinator.upload_utils.handle_upload_request ( int  content_length,
str  content_boundary,
bytes  expect_digest,
io.BufferedIOBase  stream,
str  file_name 
)
Given sufficient header data and an input stream, stream raw content to a
file, hashing it at the same time to verify the given signature.

Definition at line 72 of file upload_utils.py.

73  content_length: int,
74  content_boundary: str,
75  expect_digest: bytes,
76  stream: io.BufferedIOBase,
77  file_name: str) -> None:
78  """
79  Given sufficient header data and an input stream, stream raw content to a
80  file, hashing it at the same time to verify the given signature.
81  """
82 
83  final_boundary = f"\r\n--{content_boundary}--\r\n"
84  final_boundary_size = len(final_boundary)
85 
86  # Expect the stream to be formatted:
87  # --------------------------985b875979d96dfa <boundary>
88  # Content-Disposition: form-data; .... <part-header>
89  # Content-Type: application/octet-stream <part-header>
90  # ... <part-header>
91  # <blank-line>
92  # <raw-content> <part-data>
93  # --------------------------985b875979d96dfa-- <final-boundary>
94  # Note, for simplicity we assume content is single-part
95 
96  remaining_bytes = content_length - final_boundary_size
97 
98  # Skip the headers
99  header_bytes = _read_part_headers(stream)
100  remaining_bytes = remaining_bytes - header_bytes
101 
102  # Read up to the final boundary,
103  # print(f"expecting {remaining_bytes} file bytes")
104  digest = _read_to_file(stream, file_name, remaining_bytes)
105  if digest is None:
106  raise Exception("invalid part format")
107  if digest != expect_digest:
108  raise Exception("digest mismatch")
109 
110  # Read final boundary and sanity check
111  tail = _read_to_memory(stream, final_boundary_size)
112  if tail is None or tail.decode() != final_boundary:
113  raise Exception("invalid part tail")
Here is the caller graph for this function:

Variable Documentation

◆ READ_CHUNK_SIZE

int coordinator.upload_utils.READ_CHUNK_SIZE = 4096

Definition at line 11 of file upload_utils.py.

coordinator.upload_utils.handle_upload_request
None handle_upload_request(int content_length, str content_boundary, bytes expect_digest, io.BufferedIOBase stream, str file_name)
Definition: upload_utils.py:72