src/vs/base/parts/ipc/node/ipc.net.ts/WebSocketNodeSocket/_acceptChunk
class WebSocketNodeSocket:	private _acceptChunk(data: VSBuffer): void {
		if (data.byteLength === 0) {
			return;
		}
		this._totalIncomingWireBytes += data.byteLength;

		this._incomingData.acceptChunk(data);

		while (this._incomingData.byteLength >= this._state.readLen) {

			if (this._state.state === ReadState.PeekHeader) {
				// peek to see if we can read the entire header
				const peekHeader = this._incomingData.peek(this._state.readLen);
				const firstByte = peekHeader.readUInt8(0);
				const finBit = (firstByte & 0b10000000) >>> 7;
				const secondByte = peekHeader.readUInt8(1);
				const hasMask = (secondByte & 0b10000000) >>> 7;
				const len = (secondByte & 0b01111111);

				this._state.state = ReadState.ReadHeader;
				this._state.readLen = Constants.MinHeaderByteSize + (hasMask ? 4 : 0) + (len === 126 ? 2 : 0) + (len === 127 ? 8 : 0);
				this._state.fin = finBit;
				this._state.mask = 0;

			} else if (this._state.state === ReadState.ReadHeader) {
				// read entire header
				const header = this._incomingData.read(this._state.readLen);
				const secondByte = header.readUInt8(1);
				const hasMask = (secondByte & 0b10000000) >>> 7;
				let len = (secondByte & 0b01111111);

				let offset = 1;
				if (len === 126) {
					len = (
						header.readUInt8(++offset) * 2 ** 8
						+ header.readUInt8(++offset)
					);
				} else if (len === 127) {
					len = (
						header.readUInt8(++offset) * 0
						+ header.readUInt8(++offset) * 0
						+ header.readUInt8(++offset) * 0
						+ header.readUInt8(++offset) * 0
						+ header.readUInt8(++offset) * 2 ** 24
						+ header.readUInt8(++offset) * 2 ** 16
						+ header.readUInt8(++offset) * 2 ** 8
						+ header.readUInt8(++offset)
					);
				}

				let mask = 0;
				if (hasMask) {
					mask = (
						header.readUInt8(++offset) * 2 ** 24
						+ header.readUInt8(++offset) * 2 ** 16
						+ header.readUInt8(++offset) * 2 ** 8
						+ header.readUInt8(++offset)
					);
				}

				this._state.state = ReadState.ReadBody;
				this._state.readLen = len;
				this._state.mask = mask;

			} else if (this._state.state === ReadState.ReadBody) {
				// read body

				const body = this._incomingData.read(this._state.readLen);
				unmask(body, this._state.mask);

				this._state.state = ReadState.PeekHeader;
				this._state.readLen = Constants.MinHeaderByteSize;
				this._state.mask = 0;

				if (this._zlibInflate) {
					// See https://tools.ietf.org/html/rfc7692#section-7.2.2
					if (this._recordInflateBytes) {
						this._recordedInflateBytes.push(Buffer.from(<Buffer>body.buffer));
					}
					this._zlibInflate.write(<Buffer>body.buffer);
					if (this._state.fin) {
						if (this._recordInflateBytes) {
							this._recordedInflateBytes.push(Buffer.from([0x00, 0x00, 0xff, 0xff]));
						}
						this._zlibInflate.write(Buffer.from([0x00, 0x00, 0xff, 0xff]));
					}
					this._zlibInflate.flush(() => {
						const data = Buffer.concat(this._pendingInflateData);
						this._pendingInflateData.length = 0;
						this._totalIncomingDataBytes += data.length;
						this._onData.fire(VSBuffer.wrap(data));
					});
				} else {
					this._totalIncomingDataBytes += body.byteLength;
					this._onData.fire(body);
				}
			}
		}
	}