Skip to content

Commit 0c3098b

Browse files
committed
read and write unsigned char more efficiently
1 parent 6e5bee0 commit 0c3098b

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

libarchive/entry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from contextlib import contextmanager
2-
from ctypes import create_string_buffer
2+
from ctypes import create_string_buffer, string_at
33
from enum import IntEnum
44
import math
55

@@ -502,7 +502,7 @@ def get_stored_digest(self, algorithm_name):
502502
f"the libarchive being used (version {ffi.version_number()}, path "
503503
f"{ffi.libarchive_path}) doesn't support {algorithm_name} digests"
504504
) from None
505-
return bytes(ptr[:algorithm.bytes_length])
505+
return string_at(ptr, algorithm.bytes_length)
506506

507507
def set_stored_digest(self, algorithm_name, value):
508508
algorithm = ffi.DIGEST_ALGORITHMS[algorithm_name]
@@ -516,7 +516,7 @@ def set_stored_digest(self, algorithm_name, value):
516516
retcode = ffi.entry_set_digest(
517517
self._entry_p,
518518
algorithm.libarchive_id,
519-
(expected_length * ffi.c_ubyte)(*value)
519+
(expected_length * ffi.c_ubyte).from_buffer_copy(value)
520520
)
521521
except AttributeError:
522522
raise NotImplementedError(

0 commit comments

Comments
 (0)