Skip to content

Commit c931af3

Browse files
committed
replace the misleadingly named VOID_CB function
1 parent 0323df6 commit c931af3

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

libarchive/ffi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
)
5252
OPEN_CALLBACK = CFUNCTYPE(c_int, c_void_p, c_void_p)
5353
CLOSE_CALLBACK = CFUNCTYPE(c_int, c_void_p, c_void_p)
54-
VOID_CB = lambda *_: ARCHIVE_OK
54+
55+
NO_OPEN_CB = ctypes.cast(None, OPEN_CALLBACK)
56+
NO_CLOSE_CB = ctypes.cast(None, CLOSE_CALLBACK)
5557

5658

5759
# Type aliases, for readability

libarchive/read.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from . import ffi
66
from .ffi import (
77
ARCHIVE_EOF, OPEN_CALLBACK, READ_CALLBACK, CLOSE_CALLBACK, SEEK_CALLBACK,
8-
VOID_CB, page_size,
8+
NO_OPEN_CB, NO_CLOSE_CB, page_size,
99
)
1010
from .entry import ArchiveEntry, new_archive_entry
1111

@@ -57,14 +57,14 @@ def new_archive_read(format_name='all', filter_name='all', passphrase=None):
5757
@contextmanager
5858
def custom_reader(
5959
read_func, format_name='all', filter_name='all',
60-
open_func=VOID_CB, seek_func=None, close_func=VOID_CB,
60+
open_func=None, seek_func=None, close_func=None,
6161
block_size=page_size, archive_read_class=ArchiveRead, passphrase=None,
6262
):
6363
"""Read an archive using a custom function.
6464
"""
65-
open_cb = OPEN_CALLBACK(open_func)
65+
open_cb = OPEN_CALLBACK(open_func) if open_func else NO_OPEN_CB
6666
read_cb = READ_CALLBACK(read_func)
67-
close_cb = CLOSE_CALLBACK(close_func)
67+
close_cb = CLOSE_CALLBACK(close_func) if close_func else NO_CLOSE_CB
6868
with new_archive_read(format_name, filter_name, passphrase) as archive_p:
6969
if seek_func:
7070
ffi.read_set_seek_callback(archive_p, SEEK_CALLBACK(seek_func))
@@ -140,9 +140,9 @@ def seek_func(archive_p, context, offset, whence):
140140
# tell libarchive the current position
141141
return stream.tell()
142142

143-
open_cb = OPEN_CALLBACK(VOID_CB)
143+
open_cb = NO_OPEN_CB
144144
read_cb = READ_CALLBACK(read_func)
145-
close_cb = CLOSE_CALLBACK(VOID_CB)
145+
close_cb = NO_CLOSE_CB
146146
with new_archive_read(format_name, filter_name, passphrase) as archive_p:
147147
if stream.seekable():
148148
ffi.read_set_seek_callback(archive_p, SEEK_CALLBACK(seek_func))

libarchive/write.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from . import ffi
66
from .entry import ArchiveEntry, new_archive_entry
77
from .ffi import (
8-
OPEN_CALLBACK, WRITE_CALLBACK, CLOSE_CALLBACK, VOID_CB, REGULAR_FILE,
9-
DEFAULT_UNIX_PERMISSION, ARCHIVE_EOF,
8+
OPEN_CALLBACK, WRITE_CALLBACK, CLOSE_CALLBACK, NO_OPEN_CB, NO_CLOSE_CB,
9+
REGULAR_FILE, DEFAULT_UNIX_PERMISSION, ARCHIVE_EOF,
1010
page_size, entry_sourcepath, entry_clear, read_disk_new, read_disk_open_w,
1111
read_next_header2, read_disk_descend, read_free, write_header, write_data,
1212
write_finish_entry, entry_set_size, entry_set_filetype, entry_set_perm,
@@ -187,17 +187,17 @@ def new_archive_write(format_name, filter_name=None, options='', passphrase=None
187187
@contextmanager
188188
def custom_writer(
189189
write_func, format_name, filter_name=None,
190-
open_func=VOID_CB, close_func=VOID_CB, block_size=page_size,
190+
open_func=None, close_func=None, block_size=page_size,
191191
archive_write_class=ArchiveWrite, options='', passphrase=None,
192192
):
193193

194194
def write_cb_internal(archive_p, context, buffer_, length):
195195
data = cast(buffer_, POINTER(c_char * length))[0]
196196
return write_func(data)
197197

198-
open_cb = OPEN_CALLBACK(open_func)
198+
open_cb = OPEN_CALLBACK(open_func) if open_func else NO_OPEN_CB
199199
write_cb = WRITE_CALLBACK(write_cb_internal)
200-
close_cb = CLOSE_CALLBACK(close_func)
200+
close_cb = CLOSE_CALLBACK(close_func) if close_func else NO_CLOSE_CB
201201

202202
with new_archive_write(format_name, filter_name, options,
203203
passphrase) as archive_p:

0 commit comments

Comments
 (0)