MCPcopy Index your code
hub / github.com/RustPython/RustPython / a85encode

Function a85encode

Lib/base64.py:323–362  ·  view source on GitHub ↗

Encode bytes-like object b using Ascii85 and return a bytes object. foldspaces is an optional flag that uses the special short sequence 'y' instead of 4 consecutive spaces (ASCII 0x20) as supported by 'btoa'. This feature is not supported by the "standard" Adobe encoding. wrapcol c

(b, *, foldspaces=False, wrapcol=0, pad=False, adobe=False)

Source from the content-addressed store, hash-verified

321 return b''.join(chunks)
322
323def a85encode(b, *, foldspaces=False, wrapcol=0, pad=False, adobe=False):
324 """Encode bytes-like object b using Ascii85 and return a bytes object.
325
326 foldspaces is an optional flag that uses the special short sequence 'y'
327 instead of 4 consecutive spaces (ASCII 0x20) as supported by 'btoa'. This
328 feature is not supported by the "standard" Adobe encoding.
329
330 wrapcol controls whether the output should have newline (b'\\n') characters
331 added to it. If this is non-zero, each output line will be at most this
332 many characters long, excluding the trailing newline.
333
334 pad controls whether the input is padded to a multiple of 4 before
335 encoding. Note that the btoa implementation always pads.
336
337 adobe controls whether the encoded byte sequence is framed with <~ and ~>,
338 which is used by the Adobe implementation.
339 """
340 global _a85chars, _a85chars2
341 # Delay the initialization of tables to not waste memory
342 # if the function is never called
343 if _a85chars2 is None:
344 _a85chars = [bytes((i,)) for i in range(33, 118)]
345 _a85chars2 = [(a + b) for a in _a85chars for b in _a85chars]
346
347 result = _85encode(b, _a85chars, _a85chars2, pad, True, foldspaces)
348
349 if adobe:
350 result = _A85START + result
351 if wrapcol:
352 wrapcol = max(2 if adobe else 1, wrapcol)
353 chunks = [result[i: i + wrapcol]
354 for i in range(0, len(result), wrapcol)]
355 if adobe:
356 if len(chunks[-1]) + 2 > wrapcol:
357 chunks.append(b'')
358 result = b'\n'.join(chunks)
359 if adobe:
360 result += _A85END
361
362 return result
363
364def a85decode(b, *, foldspaces=False, adobe=False, ignorechars=b' \t\n\r\v'):
365 """Decode the Ascii85 encoded bytes-like object or ASCII string b.

Callers

nothing calls this directly

Calls 5

_85encodeFunction · 0.85
maxFunction · 0.85
lenFunction · 0.85
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected