MCPcopy Create free account
hub / github.com/scriptscat/scriptcat / getChunkEnd

Function getChunkEnd

src/pkg/utils/istextorbinary.ts:146–189  ·  view source on GitHub ↗
(buf: Uint8Array, chunkEnd: number)

Source from the content-addressed store, hash-verified

144}
145
146function getChunkEnd(buf: Uint8Array, chunkEnd: number) {
147 // If it's the end, just return.
148 if (chunkEnd === buf.length) {
149 return chunkEnd;
150 }
151
152 let index = chunkEnd - 3;
153
154 if (index >= 0) {
155 if (isFirstByteOf4ByteChar(buf[index])) {
156 return chunkEnd + 1;
157 }
158 }
159
160 index = chunkEnd - 2;
161
162 if (index >= 0) {
163 if (isFirstByteOf4ByteChar(buf[index])) {
164 return chunkEnd + 2;
165 }
166
167 if (isFirstByteOf3ByteChar(buf[index])) {
168 return chunkEnd + 1;
169 }
170 }
171
172 index = chunkEnd - 1;
173
174 if (index >= 0) {
175 if (isFirstByteOf4ByteChar(buf[index])) {
176 return chunkEnd + 3;
177 }
178
179 if (isFirstByteOf3ByteChar(buf[index])) {
180 return chunkEnd + 2;
181 }
182
183 if (isFirstByteOf2ByteChar(buf[index])) {
184 return chunkEnd + 1;
185 }
186 }
187
188 return chunkEnd;
189}
190
191function isFirstByteOf4ByteChar(byte: number) {
192 return byte >> 3 === 30; // 11110xxx?

Callers 1

getEncodingFunction · 0.85

Calls 3

isFirstByteOf4ByteCharFunction · 0.85
isFirstByteOf3ByteCharFunction · 0.85
isFirstByteOf2ByteCharFunction · 0.85

Tested by

no test coverage detected