-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathbuffer_data.py
More file actions
47 lines (35 loc) · 1.51 KB
/
Copy pathbuffer_data.py
File metadata and controls
47 lines (35 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#
# This file is part of libdebug Python library (https://github.com/libdebug/libdebug).
# Copyright (c) 2024 Gabriele Digregorio. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for details.
#
from __future__ import annotations
class BufferData:
"""Class that represents a buffer to store data coming from stdout and stderr."""
def __init__(self: BufferData, data: bytes) -> None:
"""Initializes the BufferData object."""
self.data = data
def clear(self: BufferData) -> None:
"""Clears the buffer."""
self.data = b""
def get_data(self: BufferData) -> bytes:
"""Returns the data stored in the buffer."""
return self.data
def append(self, data: bytes) -> None:
"""Appends data to the buffer."""
self.data += data
def overwrite(self, data: bytes) -> None:
"""Overwrites the buffer with the given data."""
self.data = data
def find(self: BufferData, pattern: bytes) -> int:
"""Finds the first occurrence of the given pattern in the buffer."""
return self.data.find(pattern)
def __len__(self: BufferData) -> int:
"""Returns the length of the buffer."""
return len(self.data)
def __repr__(self: BufferData) -> str:
"""Returns a string representation of the buffer."""
return self.data.__repr__()
def __getitem__(self: BufferData, key: int) -> bytes:
"""Returns the item at the given index."""
return self.data[key]