MCPcopy Create free account
hub / github.com/Effect-TS/effect / advance

Method advance

packages/effect/src/encoding/Tar.ts:1197–1256  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1195 }
1196
1197 private advance(): Header | undefined | typeof NeedInput {
1198 this.generation++
1199 this.skip += this.remaining + this.pad
1200 this.remaining = 0
1201 this.pad = 0
1202 const queue = this.queue
1203 while (true) {
1204 if (this.finished) return this.finish()
1205 while (this.skip > 0) {
1206 if (queue.length === 0) return this.needInput()
1207 this.skip -= queue.takeSome(this.skip).length
1208 }
1209 if (this.meta !== undefined) {
1210 const { size, typeflag } = this.meta
1211 const total = size + padding(size)
1212 if (queue.length < total) return this.needInput()
1213 const data = queue.take(total).subarray(0, size)
1214 this.meta = undefined
1215 if (typeflag === "x") this.pax = parsePax(data)
1216 else if (typeflag === "g") this.addGlobal(parsePax(data))
1217 else if (typeflag === "L") this.longName = readString(data, 0, size)
1218 else this.longLink = readString(data, 0, size)
1219 continue
1220 }
1221 if (queue.length < BLOCK) {
1222 if (queue.length === 0 && this.ended) return this.finish()
1223 return this.needInput()
1224 }
1225 this.at = queue.consumed
1226 const block = queue.take(BLOCK)
1227 if (isZeroBlock(block)) {
1228 if (this.zeroBlock) return this.finish()
1229 this.zeroBlock = true
1230 continue
1231 }
1232 if (this.zeroBlock) {
1233 throw invalidHeader("non-zero block after an end-of-archive block")
1234 }
1235 const raw = parseHeader(block)
1236 switch (raw.typeflag) {
1237 case "x":
1238 case "g":
1239 case "L":
1240 case "K": {
1241 if (raw.size > MAX_META_SIZE) {
1242 throw invalidHeader(`extended header of ${raw.size} bytes exceeds the limit`)
1243 }
1244 this.meta = raw
1245 continue
1246 }
1247 case "S": {
1248 throw unsupported("GNU sparse files are not supported")
1249 }
1250 }
1251 const header = this.toHeader(raw)
1252 this.remaining = header.size
1253 this.pad = padding(header.size)
1254 return header

Callers 2

nextMethod · 0.95

Calls 13

finishMethod · 0.95
needInputMethod · 0.95
addGlobalMethod · 0.95
toHeaderMethod · 0.95
parsePaxFunction · 0.85
isZeroBlockFunction · 0.85
paddingFunction · 0.70
readStringFunction · 0.70
invalidHeaderFunction · 0.70
parseHeaderFunction · 0.70
unsupportedFunction · 0.70
takeMethod · 0.65

Tested by

no test coverage detected