(text: string, prefix: number)
| 171 | |
| 172 | /** As `encodeUtf8`, but leaves `prefix` bytes free at the front. */ |
| 173 | const encodeUtf8Prefixed = (text: string, prefix: number): Uint8Array => { |
| 174 | const length = text.length |
| 175 | if (length <= asciiEncodeLimit) { |
| 176 | const bytes = new Uint8Array(prefix + length) |
| 177 | let i = 0 |
| 178 | for (; i < length; i++) { |
| 179 | const code = text.charCodeAt(i) |
| 180 | if (code > 0x7f) break |
| 181 | bytes[prefix + i] = code |
| 182 | } |
| 183 | if (i === length) return bytes |
| 184 | } |
| 185 | const written = encodeUtf8Scratch(text) |
| 186 | if (written === -1) { |
| 187 | const body = textEncoder.encode(text) |
| 188 | const bytes = new Uint8Array(prefix + body.length) |
| 189 | bytes.set(body, prefix) |
| 190 | return bytes |
| 191 | } |
| 192 | const bytes = new Uint8Array(prefix + written) |
| 193 | bytes.set(scratchUtf8.subarray(0, written), prefix) |
| 194 | return bytes |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * A view of `size` bytes at `offset`, or `bytes` itself when that is already |
no test coverage detected