summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/npm-registry-fetch/node_modules/smart-buffer/typings/index.d.ts
blob: b567f1e97c28571ff273ee0338179b3afd1c7fb5 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
// Type definitions for smart-buffer
// Project: https://github.com/JoshGlazebrook/smart-buffer
// Definitions by: Josh Glazebrook <https://github.com/JoshGlazebrook>



declare class SmartBuffer {
    /**
     * Creates a new SmartBuffer instance (defaults to utf8 encoding)
     */
    constructor();

    /**
     * Creates a new SmartBuffer instance
     *
     * @param arg1 { Number } The size the underlying buffer instance should be instantiated to (defaults to 4096)
     * @param arg2 { String } The string encoding to use for reading/writing strings (defaults to utf8)
     */
    constructor(size: number, encoding?: string);

    /**
     * Creates a new SmartBuffer instance
     *
     * @param arg1 { String } The string encoding to use for reading/writing strings (defaults to utf8)
     */
    constructor(encoding?: string);

    /**
     * Creates a new SmartBuffer instance
     *
     * @param arg1 { Buffer } An existing buffer instance to copy to this smart buffer instance
     * @param arg2 { String } The string encoding to use for reading/writing strings (defaults to utf8)
     */
    constructor(buffer: Buffer, encoding?: string)



    // Signed number readers

    /**
     * Reads a 8-bit signed integer
     */
    readInt8(): number;

    /**
     * Reads a 16-bit signed integer (big endian)
     */
    readInt16BE(): number;

    /**
     * Reads a 16-bit signed integer (little endian)
     */
    readInt16LE(): number;

    /**
     * Reads a 32-bit signed integer (big endian)
     */
    readInt32BE(): number;

    /**
     * Reads a 32-bit signed integer (little endian)
     */
    readInt32LE(): number;

    // Unsigned number readers

    /**
     * Reads a 8-bit unsigned integer
     */
    readUInt8(): number;

    /**
     * Reads a 16-bit unsigned integer (big endian)
     */
    readUInt16BE(): number;

    /**
     * Reads a 16-bit unsigned integer (little endian)
     */
    readUInt16LE(): number;

    /**
     * Reads a 32-bit unsigned integer (big endian)
     */
    readUInt32BE(): number;

    /**
     * Reads a 32-bit unsigned integer (little endian)
     */
    readUInt32LE(): number;

    // Floating point readers

    /**
     * Reads a float (big endian)
     */
    readFloatBE(): number;

    /**
     * Reads a float (little endian)
     */
    readFloatLE(): number;

    /**
     * Reads a double (big endian)
     */
    readDoubleBE(): number;

    /**
     * Reads a double (little endian)
     */
    readDoubleLE(): number;

    // String readers

    /**
     * Reads a string
     *
     * @param length { Number } The length of the string to read
     * @param encoding { Number} The encoding to use (defaults to instance level encoding)
     */
    readString(length?: number, encoding?: string): string;

    /**
     * Reads a null terminated string
     *
     * @param encoding The encoding to use (defaults to instance level encoding)
     */
    readStringNT(encoding?: string): string;

    // Buffer readers

    /**
     * Reads binary data into a Buffer
     *
     * @param len { Number } The amount of data to read
     */
    readBuffer(len?: number): Buffer;

    /**
     * Reads null terminated binary data into a Buffer
     */
    readBufferNT(): Buffer;


    // Signed number writers

    /**
     * Writes a 8-bit signed integer value
     *
     * @param value { Number } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     */
    writeInt8(value: number, offset?: number): this;

    /**
     * Writes a 16-bit signed integer (big endian) value
     *
     * @param value { Number } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     */
    writeInt16BE(value: number, offset?: number): this;

    /**
     * Writes a 16-bit signed integer (little endian) value
     *
     * @param value { Number } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     */
    writeInt16LE(value: number, offset?: number): this;

    /**
     * Writes a 32-bit signed integer (big endian) value
     *
     * @param value { Number } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     */
    writeInt32BE(value: number, offset?: number): this;

    /**
     * Writes a 32-bit signed integer (little endian) value
     *
     * @param value { Number } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     */
    writeInt32LE(value: number, offset?: number): this;

    // Unsigned number writers

    /**
     * Writes a 8-bit unsigned integer value
     *
     * @param value { Number } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     */
    writeUInt8(value: number, offset?: number): this;

    /**
     * Writes a 16-bit unsigned integer (big endian) value
     *
     * @param value { Number } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     */
    writeUInt16BE(value: number, offset?: number): this;

    /**
     * Writes a 16-bit unsigned integer (little endian) value
     *
     * @param value { Number } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     */
    writeUInt16LE(value: number, offset?: number): this;

    /**
     * Writes a 32-bit unsigned integer (big endian) value
     *
     * @param value { Number } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     */
    writeUInt32BE(value: number, offset?: number): this;

    /**
     * Writes a 32-bit unsigned integer (little endian) value
     *
     * @param value { Number } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     */
    writeUInt32LE(value: number, offset?: number): this;

    // Floating point writers

    /**
     * Writes a float (big endian) value
     *
     * @param value { Number } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     */
    writeFloatBE(value: number, offset?: number): this;

    /**
     * Writes a float (little endian) value
     *
     * @param value { Number } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     */
    writeFloatLE(value: number, offset?: number): this;

    /**
     * Writes a double (big endian) value
     *
     * @param value { Number } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     */
    writeDoubleBE(value: number, offset?: number): this;

    /**
     * Writes a double (little endian) value
     *
     * @param value { Number } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     */
    writeDoubleLE(value: number, offset?: number): this;

    // String writers

    /**
     * Writes a string
     *
     * @param value { String } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     */
    /**
     * Writes a string
     *
     * @param value { String } The value to write to the buffer
     * @param offset { String } The encoding to use when writing the string (defaults to instance level encoding)
     */
    /**
     * Writes a string
     *
     * @param value { String } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     * @param encoding { String } The encoding to use when writing the string (defaults to instance level encoding)
     */
    writeString(value: string, offset?: number | string, encoding?: string): this;

    /**
     * Writes a null terminated string
     *
     * @param value { String } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     */
    /**
     * Writes a null terminated string
     *
     * @param value { String } The value to write to the buffer
     * @param offset { String } The encoding to use when writing the string (defaults to instance level encoding)
     */
    /**
     * Writes a null terminated string
     *
     * @param value { String } The value to write to the buffer
     * @param offset { Number } The offset position to write the value to
     * @param encoding { String } The encoding to use when writing the string (defaults to instance level encoding)
     */
    writeStringNT(value: string, offset?: number | string, encoding?: string): this;

    // Buffer writers

    /**
     * Writes a Buffer
     *
     * @param value { Buffer } The Buffer to write to the smart buffer
     * @param offset { Number } The offset position to write the value to
     */
    writeBuffer(value: Buffer, offset?: number): this;

    /**
     * Writes a Buffer with null termination
     *
     * @param value { Buffer } The buffer to write to the smart buffer
     * @param offset { Number } The offset position to write the value to
     */
    writeBufferNT(value: Buffer, offset?: number): this;


    // Misc Functions

    /**
     * Clears the smart buffer
     */
    clear();

    /**
     * Gets the number of bytes that remain to be read
     */
    remaining(): number;

    /**
     * Increases the read offset position
     *
     * @param amount { Number } The amount to increase the read offset position by
     */
    skip(amount: number);

    /**
     * Changes the read offset position
     *
     * @param position { Number } The position to change the read offset to
     */
    skipTo(position: number);

    /**
     * Decreases the read offset position
     *
     * @param amount { Number } The amount to decrease the read offset position by
     */
    rewind(amount: number);

    /**
     * Gets the underlying Buffer instance
     */
    toBuffer(): Buffer;

    /**
     * Gets the string representation of the underlying Buffer
     *
     * @param encoding { String } The encoding to use (defaults to instance level encoding)
     */
    toString(encoding?: string): string;

    /**
     * Destroys the smart buffer instance
     */
    destroy();

    /**
     * Gets the current length of the smart buffer instance
     */
    length: number;
}

export = SmartBuffer;