MCPcopy Create free account
hub / github.com/GoogleChromeLabs/ui-element-samples / transform

Method transform

stream-progress/stream.js:31–69  ·  view source on GitHub ↗
(chunk, controller)

Source from the content-addressed store, hash-verified

29 start() {}
30 flush() {}
31 transform(chunk, controller) {
32 for(let i = 0; i < chunk.length; i++) {
33 if(this.skipNext) {
34 this.skipNext = false;
35 continue;
36 }
37 const byte = chunk[i];
38 const char = String.fromCharCode(byte);
39 switch(char) {
40 case '{':
41 if(this.inString) continue;
42 this.depth++;
43 break;
44 case '}':
45 if(this.inString) continue;
46 this.depth--;
47 if(this.depth === 0) {
48 const tail = new Uint8Array(chunk.buffer, chunk.byteOffset, i + 1);
49 chunk = new Uint8Array(chunk.buffer, chunk.byteOffset + i + 1);
50 this.chunks.push(tail);
51
52 const jsonStr = this.chunks.reduce((str, chunk) =>
53 str + this.decoder.decode(chunk, {stream: true}), '');
54 controller.enqueue(jsonStr);
55
56 this.chunks.length = 0;
57 i = -1;
58 }
59 break;
60 case '"':
61 this.inString = !this.inString;
62 break;
63 case '\\':
64 this.skipNext = true;
65 break;
66 }
67 }
68 this.chunks.push(chunk);
69 }
70}
71
72const dial = document.querySelector('sc-dial');

Callers 3

rewriteFunction · 0.80
bundleFunction · 0.80
buildDependencyTreeFunction · 0.80

Calls 1

enqueueMethod · 0.80

Tested by

no test coverage detected