def parse_events(data):
"""Parse data read from an inotify file descriptor into list of
:attr:`~inotify_simple.Event` namedtuples (wd, mask, cookie, name). This
function can be used if you have decided to call ``os.read()`` on the
inotify file descriptor yourself, instead of calling
:func:`~inotify_simple.INotify.read`.
Args:
data (bytes): A bytestring as read from an inotify file descriptor
Returns:
list: list of :attr:`~inotify_simple.Event` namedtuples"""
events = []
offset = 0
buffer_size = len(data)
while offset < buffer_size:
wd, mask, cookie, namesize = struct.unpack_from(_EVENT_STRUCT_FORMAT, data, offset)
offset += _EVENT_STRUCT_SIZE
name = _fsdecode(ctypes.c_buffer(data[offset:offset + namesize], namesize).value)
offset += namesize
events.append(Event(wd, mask, cookie, name))
return events
评论列表
文章目录