MCPcopy Create free account
hub / github.com/WICG/webpackage / getResponse

Method getResponse

js/bundle/src/decoder.ts:137–154  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

135 constructor(private bundle: Bundle) {}
136
137 getResponse(url: string): Response {
138 const indexEntry = asArray(this.bundle.indexSection.get(url));
139 if (!indexEntry) {
140 throw new Error('No entry for ' + url);
141 }
142 const [variants, offset, length] = indexEntry;
143 if (asBytestring(variants).length !== 0) {
144 throw new Error('Variants are not supported');
145 }
146 if (indexEntry.length !== 3) {
147 throw new Error('Unexpected length of index entry for ' + url);
148 }
149 const resp = this.bundle.responses[asNumber(offset)];
150 if (!resp) {
151 throw new Error(`Response for ${url} is not found (broken index)`);
152 }
153 return resp;
154 }
155
156 destructureBundle(wbn: unknown[]): [any, any, any, any, any, any] {
157 return [wbn[0], wbn[1], wbn[2], wbn[3], wbn[4], wbn[5]];

Callers

nothing calls this directly

Calls 3

asArrayFunction · 0.85
asBytestringFunction · 0.85
asNumberFunction · 0.85

Tested by

no test coverage detected