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

Method flush

packages/effect/src/encoding/Zip.ts:1056–1088  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1054
1055 // Hands out the buffered output, joining runs of small chunks; needs `buffered > 0`
1056 flush(): Arr.NonEmptyArray<Uint8Array> {
1057 const out: Array<Uint8Array> = []
1058 let run: Array<Uint8Array> = []
1059 let runLength = 0
1060 const join = () => {
1061 if (run.length === 1) {
1062 out.push(run[0])
1063 } else if (run.length > 1) {
1064 const joined = new Uint8Array(runLength)
1065 let at = 0
1066 for (const chunk of run) {
1067 joined.set(chunk, at)
1068 at += chunk.length
1069 }
1070 out.push(joined)
1071 }
1072 run = []
1073 runLength = 0
1074 }
1075 for (const chunk of this.chunks) {
1076 if (chunk.length >= COPY_LIMIT) {
1077 join()
1078 out.push(chunk)
1079 } else {
1080 run.push(chunk)
1081 runLength += chunk.length
1082 }
1083 }
1084 join()
1085 this.chunks = []
1086 this.buffered = 0
1087 return out as Arr.NonEmptyArray<Uint8Array>
1088 }
1089
1090 private push(bytes: Uint8Array): void {
1091 if (bytes.length === 0) return

Callers 1

encodeFunction · 0.95

Calls 2

pushMethod · 0.65
joinFunction · 0.50

Tested by

no test coverage detected