Skip to content

Commit c28238f

Browse files
Simplify library
1 parent 16d3af7 commit c28238f

File tree

4 files changed

+213
-706
lines changed

4 files changed

+213
-706
lines changed

README.md

Lines changed: 23 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ Converts a list of integers into a byte.
8484

8585
Converts bytes object *b* into an integer. The endian can be specified with the *endian* argument. The *signed* argument is used to specify whether the integer is signed or not.
8686

87-
**pack_int(number, numbytes, endian=None, signed=False)**
87+
**pack_int(number, size, endian=None, signed=False)**
8888

89-
Converts *number* into a bytes object with length *numbytes* and endian *endian*. The *signed* argument is used to specify whether the integer is signed or not.
89+
Converts *number* into a bytes object with length *size* and endian *endian*. The *signed* argument is used to specify whether the integer is signed or not.
9090

91-
**unpack_float(b, numbytes, endian=None)**
91+
**unpack_float(b, size, endian=None)**
9292

93-
Converts bytes object *b* into a float. *numbytes* can be 2 for half precision, 4 for single precision, or 8 for double precision. The endian can be specified with the *endian* argument.
93+
Converts bytes object *b* into a float. *size* can be 2 for half precision, 4 for single precision, or 8 for double precision. The endian can be specified with the *endian* argument.
9494

95-
**pack_float(number, numbytes, endian=None)**
95+
**pack_float(number, size, endian=None)**
9696

97-
Converts *number* into a bytes object. *numbytes* can be 2 for half precision, 4 for single precision, or 8 for double precision. The endian can be specified with the *endian* argument.
97+
Converts *number* into a bytes object. *size* can be 2 for half precision, 4 for single precision, or 8 for double precision. The endian can be specified with the *endian* argument.
9898

9999
**unpack_str(b)**
100100

@@ -112,13 +112,13 @@ Convert bytes object *b* into a string up to the null termination. If *start* is
112112

113113
Converts *string* into a bytes object representing a null-terminated string.
114114

115-
**unpack_pstr(b, numbytes, endian=None, start=0)**
115+
**unpack_pstr(b, size, endian=None, start=0)**
116116

117-
Converts bytes object *b* into a Pascal string. *numbytes* is used to specify how many bytes are used for the string's length in the object. The endian of the length of the string can be specified with the *endian* argument. *b* will only be converted up to the length specified in the bytes object. If *start* is specified, then the bytes object will be converted starting from position *start*. Returns a tuple containing both the value and the length of the type.
117+
Converts bytes object *b* into a Pascal string. *size* is used to specify how many bytes are used for the string's length in the object. The endian of the length of the string can be specified with the *endian* argument. *b* will only be converted up to the length specified in the bytes object. If *start* is specified, then the bytes object will be converted starting from position *start*. Returns a tuple containing both the value and the length of the type.
118118

119-
**pack_pstr(string, numbytes, endian=None)**
119+
**pack_pstr(string, size, endian=None)**
120120

121-
Converts *string* into a bytes object in the Pascal string format. *numbytes* is used to specify how many bytes are used for the string's length. The endian of the length of the string can be specified with the *endian* argument.
121+
Converts *string* into a bytes object in the Pascal string format. *size* is used to specify how many bytes are used for the string's length. The endian of the length of the string can be specified with the *endian* argument.
122122

123123
**unpack_7bint(b, start=0)**
124124

@@ -158,10 +158,6 @@ Returns the size/length of the file.
158158

159159
Checks if the content of the object is equal to the content of another instance of the same object.
160160

161-
**is_eof()**
162-
163-
Return True if the end of the stream has been reached.
164-
165161
**copy()**
166162

167163
Creates a copy of the object and returns it.
@@ -170,18 +166,6 @@ Creates a copy of the object and returns it.
170166

171167
Clear the internal buffer of the object.
172168

173-
**append(b)**
174-
175-
Appends bytes object *b* to the object at the current location.
176-
177-
**overwrite(self, length, b)**
178-
179-
Overwrites *length* bytes at the current position with *b*.
180-
181-
**delete(length)**
182-
183-
Deletes *length* bytes from the object starting from the current position.
184-
185169
**find(bytes_sequence, n=1)**
186170

187171
Searches the object for *bytes_sequence*. Returns the location in which the *nth* occurrence of *bytes_sequence* can be found, returns -1 if it's not found. Starts searching from the current position in the buffer.
@@ -198,10 +182,6 @@ Read one byte from the object and converts it into a boolean.
198182

199183
Writes *boolean* to the object.
200184

201-
**append_bool()**
202-
203-
Appends *boolean* to the object.
204-
205185
**read_bits()**
206186

207187
Reads one byte from the object and converts it into a list of integers representing the individual bits in the byte. The first element in the list is LSB in the byte.
@@ -210,33 +190,21 @@ Reads one byte from the object and converts it into a list of integers represent
210190

211191
Converts list of integers *bits* into a byte and writes it to the object.
212192

213-
**append_bits(bits)**
193+
**read_int(size, endian=None, signed=False)**
214194

215-
Converts list of integers *bits* into a byte and writes it to the object.
216-
217-
**read_int(numbytes, endian=None, signed=False)**
218-
219-
Reads *numbytes* bytes from the object and converts it into an integer. The endian can be specified with the *endian* argument. The *signed* argument is used to specify whether the integer is signed or not.
220-
221-
**write_int(number, numbytes, endian=None, signed=False)**
222-
223-
Converts *number* into a bytes object with length *numbytes* and endian *endian*, then writes it into the object. The *signed* argument is used to specify whether the integer is signed or not.
195+
Reads *size* bytes from the object and converts it into an integer. The endian can be specified with the *endian* argument. The *signed* argument is used to specify whether the integer is signed or not.
224196

225-
**append_int(number, numbytes, endian=None, signed=False)**
197+
**write_int(number, size, endian=None, signed=False)**
226198

227-
Same as *write_int* but appends the value to the object at the current position instead of overwriting existing bytes.
199+
Converts *number* into a bytes object with length *size* and endian *endian*, then writes it into the object. The *signed* argument is used to specify whether the integer is signed or not.
228200

229-
**read_float(numbytes, endian=None)**
201+
**read_float(size, endian=None)**
230202

231-
Reads *numbytes* bytes from the object and converts them into a float. *numbytes* can be 2 for half precision, 4 for single precision, or 8 for double precision. The endian can be specified with the *endian* argument.
203+
Reads *size* bytes from the object and converts them into a float. *size* can be 2 for half precision, 4 for single precision, or 8 for double precision. The endian can be specified with the *endian* argument.
232204

233-
**write_float(number, numbytes, endian=None)**
205+
**write_float(number, size, endian=None)**
234206

235-
Converts *number* into a bytes object then writes it into the object. *numbytes* can be 2 for half precision, 4 for single precision, or 8 for double precision. The endian can be specified with the *endian* argument.
236-
237-
**append_float(number, numbytes, endian=None)**
238-
239-
Same as *write_float* but appends the value to the object at the current position instead of overwriting existing bytes. *numbytes* can be 2 for half precision, 4 for single precision, or 8 for double precision. The endian can be specified with the *endian* argument.
207+
Converts *number* into a bytes object then writes it into the object. *size* can be 2 for half precision, 4 for single precision, or 8 for double precision. The endian can be specified with the *endian* argument.
240208

241209
**read_str(length)**
242210

@@ -246,14 +214,6 @@ Reads a string with length *length* from the object.
246214

247215
Writes *string* into the object.
248216

249-
**append_str(string)**
250-
251-
Same as *write_str* but appends the value to the object at the current position instead of overwriting existing bytes.
252-
253-
**overwrite_str(string, length)**
254-
255-
Deletes *length* bytes starting from the current location, then writes *string* in it's place.
256-
257217
**read_cstr()**
258218

259219
Reads a string from the object up to the null termination. Raises a *ValueError* if it fails to find a null termination.
@@ -262,46 +222,22 @@ Reads a string from the object up to the null termination. Raises a *ValueError*
262222

263223
Writes *string* into the object.
264224

265-
**append_cstr(string)**
266-
267-
Same as *write_cstr* but appends the value to the object at the current position instead of overwriting existing bytes.
268-
269-
**overwrite_cstr(string)**
270-
271-
Deletes the null-terminated string existing at the current location, then writes *string* as a null-terminated string in it's place. Raises a *ValueError* if it fails to find a null termination.
272-
273225
**skip_cstr()**
274226

275227
Skips the null-terminated string at the current position.
276228

277-
**delete_cstr()**
229+
**read_pstr(size, endian=None)**
278230

279-
Deletes the null-terminated string at the current position.
231+
Reads a Pascal string from the object and returns it. *size* is used to specify how many bytes are used for the string's length in the object. The endian of the length of the string can be specified with the *endian* argument.
280232

281-
**read_pstr(numbytes, endian=None)**
282-
283-
Reads a Pascal string from the object and returns it. *numbytes* is used to specify how many bytes are used for the string's length in the object. The endian of the length of the string can be specified with the *endian* argument.
284-
285-
**write_pstr(string, numbytes, endian=None)**
233+
**write_pstr(string, size, endian=None)**
286234

287235
Writes *string* to the object as a Pascal string.
288236

289-
**append_pstr(string, numbytes, endian=None)**
290-
291-
Same as *write_pstr* but appends the value to the object at the current position instead of overwriting existing bytes.
292-
293-
**overwrite_pstr(string, numbytes, endian=None)**
294-
295-
Deletes the existing Pascal string at the current position and writes *string* as a Pascal string in it's place.
296-
297-
**skip_pstr(numbytes, endian=None)**
237+
**skip_pstr(size, endian=None)**
298238

299239
Skips the Pascal string at the current position.
300240

301-
**delete_pstr(numbytes, endian=None)**
302-
303-
Deletes the Pascal string at the current position.
304-
305241
**read_7bint()**
306242

307243
Reads the bytes representing a 7 bit integer from the object at the current position and converts them into an integer.
@@ -310,18 +246,6 @@ Reads the bytes representing a 7 bit integer from the object at the current posi
310246

311247
Converts *number* into a 7 bit integer and writes it to the object.
312248

313-
**append_7bint(number)**
314-
315-
Converts *number* into a 7 bit integer and appends it to the object.
316-
317-
**overwrite_7bint(number)**
318-
319-
Overwrites the 7 bit integer at the current position with *number*.
320-
321249
**skip_7bint()**
322250

323-
Skips the 7 bit integer at the current position.
324-
325-
**delete_7bint()**
326-
327-
Deletes the 7 bit integer at the current position.
251+
Skips the 7 bit integer at the current position.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "structio"
7-
version = "1.3.7"
7+
version = "1.4.0"
88
description = "A Library for unparsing, parsing, and editing binary files"
99
readme = "README.md"
10-
requires-python = ">=3.2"
10+
requires-python = ">=3.8"
1111

1212
[project.urls]
1313
"Homepage" = "https://github.com/lingeringwillx/StructIO"

0 commit comments

Comments
 (0)