MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / add_content

Method add_content

pipcl.py:3234–3250  ·  view source on GitHub ↗
(self, content, to_, verbose=True)

Source from the content-addressed store, hash-verified

3232 self.text = ''
3233
3234 def add_content(self, content, to_, verbose=True):
3235 if isinstance(content, str):
3236 content = content.encode('utf8')
3237
3238 # Specification for the line we write is supposed to be in
3239 # https://packaging.python.org/en/latest/specifications/binary-distribution-format
3240 # but it's not very clear.
3241 #
3242 h = hashlib.sha256(content)
3243 digest = h.digest()
3244 digest = base64.urlsafe_b64encode(digest)
3245 digest = digest.rstrip(b'=')
3246 digest = digest.decode('utf8')
3247
3248 self.text += f'{to_},sha256={digest},{len(content)}\n'
3249 if verbose:
3250 log2(f'Adding {to_}')
3251
3252 def add_file(self, from_, to_):
3253 log1(f'Adding file: {os.path.relpath(from_)} => {to_}')

Callers 4

add_fileMethod · 0.95
addMethod · 0.80
add_fileMethod · 0.80
add_strMethod · 0.80

Calls 2

log2Function · 0.85
digestMethod · 0.80

Tested by

no test coverage detected