osu-stable-db 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as readCollectionDatabase, c as Grades, d as RankedStatuses, f as UserPermissions, i as writeOsuDatabase, l as MINIMUM_SUPPORTED_VERSION, n as writeScoresDatabase, o as writeCollectionDatabase, r as readOsuDatabase, s as GameplayModes, t as readScoresDatabase, u as Mods } from "./scores-
|
|
1
|
+
import { a as readCollectionDatabase, c as Grades, d as RankedStatuses, f as UserPermissions, i as writeOsuDatabase, l as MINIMUM_SUPPORTED_VERSION, n as writeScoresDatabase, o as writeCollectionDatabase, r as readOsuDatabase, s as GameplayModes, t as readScoresDatabase, u as Mods } from "./scores-D_f7sIP0.mjs";
|
|
2
2
|
export { GameplayModes, Grades, MINIMUM_SUPPORTED_VERSION, Mods, RankedStatuses, UserPermissions, readCollectionDatabase, readOsuDatabase, readScoresDatabase, writeCollectionDatabase, writeOsuDatabase, writeScoresDatabase };
|
package/dist/node.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as readCollectionDatabase, i as writeOsuDatabase, n as writeScoresDatabase, o as writeCollectionDatabase, r as readOsuDatabase, t as readScoresDatabase } from "./scores-
|
|
1
|
+
import { a as readCollectionDatabase, i as writeOsuDatabase, n as writeScoresDatabase, o as writeCollectionDatabase, r as readOsuDatabase, t as readScoresDatabase } from "./scores-D_f7sIP0.mjs";
|
|
2
2
|
import { readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
//#region src/node.ts
|
|
4
4
|
async function readOsuDatabaseFile(path) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BinaryReader, BinaryWriter } from "osu-binary";
|
|
1
2
|
//#region src/types.ts
|
|
2
3
|
/**
|
|
3
4
|
* The minimum legacy database version supported by this library.
|
|
@@ -98,108 +99,10 @@ const Mods = {
|
|
|
98
99
|
};
|
|
99
100
|
//#endregion
|
|
100
101
|
//#region src/core/binary.ts
|
|
101
|
-
|
|
102
|
-
const textDecoder = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
103
|
-
function toUint8Array(input) {
|
|
104
|
-
return input instanceof Uint8Array ? input : new Uint8Array(input);
|
|
105
|
-
}
|
|
106
|
-
var BinaryReader = class {
|
|
107
|
-
bytes;
|
|
108
|
-
view;
|
|
109
|
-
offset = 0;
|
|
110
|
-
constructor(input) {
|
|
111
|
-
this.bytes = toUint8Array(input);
|
|
112
|
-
this.view = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength);
|
|
113
|
-
}
|
|
114
|
-
get position() {
|
|
115
|
-
return this.offset;
|
|
116
|
-
}
|
|
117
|
-
get length() {
|
|
118
|
-
return this.bytes.byteLength;
|
|
119
|
-
}
|
|
120
|
-
get remaining() {
|
|
121
|
-
return this.length - this.offset;
|
|
122
|
-
}
|
|
123
|
-
readByte() {
|
|
124
|
-
this.ensureAvailable(1);
|
|
125
|
-
const value = this.view.getUint8(this.offset);
|
|
126
|
-
this.offset += 1;
|
|
127
|
-
return value;
|
|
128
|
-
}
|
|
129
|
-
readBoolean() {
|
|
130
|
-
return this.readByte() !== 0;
|
|
131
|
-
}
|
|
132
|
-
readInt16() {
|
|
133
|
-
this.ensureAvailable(2);
|
|
134
|
-
const value = this.view.getInt16(this.offset, true);
|
|
135
|
-
this.offset += 2;
|
|
136
|
-
return value;
|
|
137
|
-
}
|
|
138
|
-
readUInt16() {
|
|
139
|
-
this.ensureAvailable(2);
|
|
140
|
-
const value = this.view.getUint16(this.offset, true);
|
|
141
|
-
this.offset += 2;
|
|
142
|
-
return value;
|
|
143
|
-
}
|
|
144
|
-
readInt32() {
|
|
145
|
-
this.ensureAvailable(4);
|
|
146
|
-
const value = this.view.getInt32(this.offset, true);
|
|
147
|
-
this.offset += 4;
|
|
148
|
-
return value;
|
|
149
|
-
}
|
|
150
|
-
readUInt32() {
|
|
151
|
-
this.ensureAvailable(4);
|
|
152
|
-
const value = this.view.getUint32(this.offset, true);
|
|
153
|
-
this.offset += 4;
|
|
154
|
-
return value;
|
|
155
|
-
}
|
|
156
|
-
readInt64() {
|
|
157
|
-
this.ensureAvailable(8);
|
|
158
|
-
const value = this.view.getBigInt64(this.offset, true);
|
|
159
|
-
this.offset += 8;
|
|
160
|
-
return value;
|
|
161
|
-
}
|
|
162
|
-
readSingle() {
|
|
163
|
-
this.ensureAvailable(4);
|
|
164
|
-
const value = this.view.getFloat32(this.offset, true);
|
|
165
|
-
this.offset += 4;
|
|
166
|
-
return value;
|
|
167
|
-
}
|
|
168
|
-
readDouble() {
|
|
169
|
-
this.ensureAvailable(8);
|
|
170
|
-
const value = this.view.getFloat64(this.offset, true);
|
|
171
|
-
this.offset += 8;
|
|
172
|
-
return value;
|
|
173
|
-
}
|
|
102
|
+
var BinaryReader$1 = class extends BinaryReader {
|
|
174
103
|
readDateTimeTicks() {
|
|
175
104
|
return this.readInt64();
|
|
176
105
|
}
|
|
177
|
-
readBytes(length) {
|
|
178
|
-
if (!Number.isInteger(length) || length < 0) throw new RangeError(`Byte length must be a non-negative integer, got ${length}.`);
|
|
179
|
-
this.ensureAvailable(length);
|
|
180
|
-
const value = this.bytes.slice(this.offset, this.offset + length);
|
|
181
|
-
this.offset += length;
|
|
182
|
-
return value;
|
|
183
|
-
}
|
|
184
|
-
readUleb128() {
|
|
185
|
-
let value = 0;
|
|
186
|
-
let shift = 0;
|
|
187
|
-
while (true) {
|
|
188
|
-
const byte = this.readByte();
|
|
189
|
-
value |= (byte & 127) << shift;
|
|
190
|
-
if ((byte & 128) === 0) return value;
|
|
191
|
-
shift += 7;
|
|
192
|
-
if (shift > 35) throw new RangeError("ULEB128 value is too large for a JavaScript number.");
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
readString() {
|
|
196
|
-
const marker = this.readByte();
|
|
197
|
-
if (marker === 0) return null;
|
|
198
|
-
if (marker !== 11) throw new Error(`Invalid string marker 0x${marker.toString(16)}.`);
|
|
199
|
-
const length = this.readUleb128();
|
|
200
|
-
const value = this.readBytes(length);
|
|
201
|
-
return textDecoder.decode(value);
|
|
202
|
-
}
|
|
203
106
|
readIntFloatPair() {
|
|
204
107
|
const intMarker = this.readByte();
|
|
205
108
|
if (intMarker !== 8) throw new Error(`Invalid Int-Float pair int marker 0x${intMarker.toString(16)}.`);
|
|
@@ -218,95 +121,11 @@ var BinaryReader = class {
|
|
|
218
121
|
isUninherited: this.readBoolean()
|
|
219
122
|
};
|
|
220
123
|
}
|
|
221
|
-
ensureAvailable(byteLength) {
|
|
222
|
-
if (this.offset + byteLength > this.length) throw new RangeError(`Attempted to read ${byteLength} byte(s) at offset ${this.offset}, but only ${this.remaining} remain.`);
|
|
223
|
-
}
|
|
224
124
|
};
|
|
225
|
-
var BinaryWriter = class {
|
|
226
|
-
buffer;
|
|
227
|
-
view;
|
|
228
|
-
bytes;
|
|
229
|
-
offset = 0;
|
|
230
|
-
constructor(initialCapacity = 64) {
|
|
231
|
-
if (!Number.isInteger(initialCapacity) || initialCapacity <= 0) throw new RangeError(`Initial capacity must be a positive integer, got ${initialCapacity}.`);
|
|
232
|
-
this.buffer = new ArrayBuffer(initialCapacity);
|
|
233
|
-
this.view = new DataView(this.buffer);
|
|
234
|
-
this.bytes = new Uint8Array(this.buffer);
|
|
235
|
-
}
|
|
236
|
-
get position() {
|
|
237
|
-
return this.offset;
|
|
238
|
-
}
|
|
239
|
-
writeByte(value) {
|
|
240
|
-
this.ensureCapacity(1);
|
|
241
|
-
this.view.setUint8(this.offset, value);
|
|
242
|
-
this.offset += 1;
|
|
243
|
-
}
|
|
244
|
-
writeBoolean(value) {
|
|
245
|
-
this.writeByte(value ? 1 : 0);
|
|
246
|
-
}
|
|
247
|
-
writeInt16(value) {
|
|
248
|
-
this.ensureCapacity(2);
|
|
249
|
-
this.view.setInt16(this.offset, value, true);
|
|
250
|
-
this.offset += 2;
|
|
251
|
-
}
|
|
252
|
-
writeUInt16(value) {
|
|
253
|
-
this.ensureCapacity(2);
|
|
254
|
-
this.view.setUint16(this.offset, value, true);
|
|
255
|
-
this.offset += 2;
|
|
256
|
-
}
|
|
257
|
-
writeInt32(value) {
|
|
258
|
-
this.ensureCapacity(4);
|
|
259
|
-
this.view.setInt32(this.offset, value, true);
|
|
260
|
-
this.offset += 4;
|
|
261
|
-
}
|
|
262
|
-
writeUInt32(value) {
|
|
263
|
-
this.ensureCapacity(4);
|
|
264
|
-
this.view.setUint32(this.offset, value, true);
|
|
265
|
-
this.offset += 4;
|
|
266
|
-
}
|
|
267
|
-
writeInt64(value) {
|
|
268
|
-
this.ensureCapacity(8);
|
|
269
|
-
this.view.setBigInt64(this.offset, value, true);
|
|
270
|
-
this.offset += 8;
|
|
271
|
-
}
|
|
272
|
-
writeSingle(value) {
|
|
273
|
-
this.ensureCapacity(4);
|
|
274
|
-
this.view.setFloat32(this.offset, value, true);
|
|
275
|
-
this.offset += 4;
|
|
276
|
-
}
|
|
277
|
-
writeDouble(value) {
|
|
278
|
-
this.ensureCapacity(8);
|
|
279
|
-
this.view.setFloat64(this.offset, value, true);
|
|
280
|
-
this.offset += 8;
|
|
281
|
-
}
|
|
125
|
+
var BinaryWriter$1 = class extends BinaryWriter {
|
|
282
126
|
writeDateTimeTicks(value) {
|
|
283
127
|
this.writeInt64(value);
|
|
284
128
|
}
|
|
285
|
-
writeBytes(value) {
|
|
286
|
-
this.ensureCapacity(value.byteLength);
|
|
287
|
-
this.bytes.set(value, this.offset);
|
|
288
|
-
this.offset += value.byteLength;
|
|
289
|
-
}
|
|
290
|
-
writeUleb128(value) {
|
|
291
|
-
if (!Number.isInteger(value) || value < 0) throw new RangeError(`ULEB128 value must be a non-negative integer, got ${value}.`);
|
|
292
|
-
let remaining = value;
|
|
293
|
-
do {
|
|
294
|
-
let byte = remaining & 127;
|
|
295
|
-
remaining >>>= 7;
|
|
296
|
-
if (remaining !== 0) byte |= 128;
|
|
297
|
-
this.writeByte(byte);
|
|
298
|
-
} while (remaining !== 0);
|
|
299
|
-
}
|
|
300
|
-
writeString(value) {
|
|
301
|
-
if (value === null) {
|
|
302
|
-
this.writeByte(0);
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
this.writeByte(11);
|
|
306
|
-
const encoded = textEncoder.encode(value);
|
|
307
|
-
this.writeUleb128(encoded.byteLength);
|
|
308
|
-
this.writeBytes(encoded);
|
|
309
|
-
}
|
|
310
129
|
writeIntFloatPair(value) {
|
|
311
130
|
this.writeByte(8);
|
|
312
131
|
this.writeInt32(value.mods);
|
|
@@ -318,29 +137,14 @@ var BinaryWriter = class {
|
|
|
318
137
|
this.writeDouble(value.offsetMs);
|
|
319
138
|
this.writeBoolean(value.isUninherited);
|
|
320
139
|
}
|
|
321
|
-
toUint8Array() {
|
|
322
|
-
return this.bytes.slice(0, this.offset);
|
|
323
|
-
}
|
|
324
|
-
ensureCapacity(additionalBytes) {
|
|
325
|
-
const required = this.offset + additionalBytes;
|
|
326
|
-
if (required <= this.buffer.byteLength) return;
|
|
327
|
-
let nextCapacity = this.buffer.byteLength;
|
|
328
|
-
while (nextCapacity < required) nextCapacity *= 2;
|
|
329
|
-
const nextBuffer = new ArrayBuffer(nextCapacity);
|
|
330
|
-
const nextBytes = new Uint8Array(nextBuffer);
|
|
331
|
-
nextBytes.set(this.bytes.subarray(0, this.offset));
|
|
332
|
-
this.buffer = nextBuffer;
|
|
333
|
-
this.bytes = nextBytes;
|
|
334
|
-
this.view = new DataView(nextBuffer);
|
|
335
|
-
}
|
|
336
140
|
};
|
|
337
141
|
//#endregion
|
|
338
142
|
//#region src/db/shared.ts
|
|
339
143
|
function createReader(input) {
|
|
340
|
-
return new BinaryReader(input);
|
|
144
|
+
return new BinaryReader$1(input);
|
|
341
145
|
}
|
|
342
146
|
function createWriter() {
|
|
343
|
-
return new BinaryWriter();
|
|
147
|
+
return new BinaryWriter$1();
|
|
344
148
|
}
|
|
345
149
|
function assertSupportedVersion(version) {
|
|
346
150
|
if (version < 20250107) throw new RangeError(`Unsupported legacy database version ${version}. Minimum supported version is ${MINIMUM_SUPPORTED_VERSION}.`);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "osu-stable-db",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"description": "TypeScript reader and writer for osu!stable database files.",
|
|
6
6
|
"author": "zzzzv",
|
|
7
7
|
"license": "MIT",
|
|
@@ -41,5 +41,8 @@
|
|
|
41
41
|
"tsdown": "^0.21.7",
|
|
42
42
|
"typescript": "^6.0.2",
|
|
43
43
|
"vitest": "^4.1.2"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"osu-binary": "^0.1.0"
|
|
44
47
|
}
|
|
45
48
|
}
|