(serialized: string)
| 13 | }); |
| 14 | |
| 15 | function parsePhpArray(serialized: string) { |
| 16 | const initial = serialized; |
| 17 | const readString = (length: number) => { |
| 18 | const buf = new TextEncoder().encode(serialized).slice(0, length); |
| 19 | const result = new TextDecoder().decode(buf); |
| 20 | serialized = serialized.slice(result.length); |
| 21 | return result; |
| 22 | }; |
| 23 | const readInt = () => { |
| 24 | let val = 0; |
| 25 | if (!'0123456789'.includes(serialized[0])) throw new Error(`Expected number, got "${serialized[0]}", initial "${initial}"`); |
| 26 | while ('0123456789'.includes(serialized[0])) { |
| 27 | val = val * 10 + +serialized[0]; |
| 28 | serialized = serialized.slice(1); |
| 29 | } |
| 30 | return val; |
| 31 | }; |
| 32 | const readToken = (token: string) => { |
| 33 | if (serialized.startsWith(token)) serialized = serialized.slice(token.length); |
| 34 | else throw new Error(`Expected token "${token}", got "${serialized.slice(0, token.length)}", initial "${initial}"`); |
| 35 | }; |
| 36 | readToken('a:'); |
| 37 | const size = readInt(); |
| 38 | readToken(':{'); |
| 39 | const result = [...Array.from({ length: size }, () => '')]; |
| 40 | for (let i = 0; i < size; i++) { |
| 41 | readToken('i:'); |
| 42 | const key = readInt(); |
| 43 | readToken(';s:'); |
| 44 | const length = readInt(); |
| 45 | readToken(':"'); |
| 46 | const value = readString(length); |
| 47 | result[key] = value; |
| 48 | readToken('";'); |
| 49 | } |
| 50 | return result; |
| 51 | } |
| 52 | |
| 53 | async function addContestFile(domainId: string, tid: ObjectId, filename: string, filepath: string) { |
| 54 | const tdoc = await ContestModel.get(domainId, tid); |
no test coverage detected