MCPcopy Index your code
hub / github.com/glideapps/quicktype / CompressedJSON

Class CompressedJSON

src/CompressedJSON.ts:54–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52};
53
54export class CompressedJSON {
55 private _rootValue: Value | undefined;
56
57 private _ctx: Context | undefined;
58 private _contextStack: Context[] = [];
59
60 private _strings: string[] = [];
61 private _stringValues: { [str: string]: Value } = {};
62 private _objects: Value[][] = [];
63 private _arrays: Value[][] = [];
64
65 constructor(
66 private readonly _makeDate: boolean,
67 private readonly _makeTime: boolean,
68 private readonly _makeDateTime: boolean
69 ) {}
70
71 async readFromStream(readStream: stream.Readable): Promise<Value> {
72 const jsonSource = makeSource();
73 jsonSource.on("startObject", this.handleStartObject);
74 jsonSource.on("endObject", this.handleEndObject);
75 jsonSource.on("startArray", this.handleStartArray);
76 jsonSource.on("endArray", this.handleEndArray);
77 jsonSource.on("startKey", this.handleStartKey);
78 jsonSource.on("endKey", this.handleEndKey);
79 jsonSource.on("startString", this.handleStartString);
80 jsonSource.on("stringChunk", this.handleStringChunk);
81 jsonSource.on("endString", this.handleEndString);
82 jsonSource.on("startNumber", this.handleStartNumber);
83 jsonSource.on("numberChunk", this.handleNumberChunk);
84 jsonSource.on("endNumber", this.handleEndNumber);
85 jsonSource.on("nullValue", this.handleNullValue);
86 jsonSource.on("trueValue", this.handleTrueValue);
87 jsonSource.on("falseValue", this.handleFalseValue);
88 const promise = new Promise<Value>(resolve => {
89 jsonSource.on("end", () => {
90 resolve(this.finish());
91 });
92 });
93 readStream.setEncoding("utf8");
94 readStream.pipe(jsonSource.input);
95 readStream.resume();
96 return promise;
97 }
98
99 getStringForValue = (v: Value): string => {
100 return this._strings[getIndex(v, Tag.InternedString)];
101 };
102
103 getObjectForValue = (v: Value): Value[] => {
104 return this._objects[getIndex(v, Tag.Object)];
105 };
106
107 getArrayForValue = (v: Value): Value[] => {
108 return this._arrays[getIndex(v, Tag.Array)];
109 };
110
111 private internString = (s: string): Value => {

Callers

nothing calls this directly

Calls 7

definedFunction · 0.90
isDateFunction · 0.90
isTimeFunction · 0.90
isDateTimeFunction · 0.90
addHashCodeFunction · 0.90
getIndexFunction · 0.85
makeValueFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…