MCPcopy Create free account
hub / github.com/ProtonDriveApps/sdk / onData

Function onData

cli/src/cli/readPasswordLine.ts:45–70  ·  view source on GitHub ↗
(chunk: Buffer | string)

Source from the content-addressed store, hash-verified

43 };
44
45 const onData = (chunk: Buffer | string) => {
46 const s = typeof chunk === 'string' ? chunk : chunk.toString('utf8');
47 for (const char of s) {
48 // Enter, new line
49 if (char === '\n' || char === '\r') {
50 finish(password);
51 return;
52 }
53 // Ctrl+D
54 if (char === '\u0004') {
55 finish(password);
56 return;
57 }
58 // Ctrl+C
59 if (char === '\u0003') {
60 cleanup();
61 process.exit(130);
62 }
63 // Backspace (delete 0x7F, backspace 0x08)
64 if (char === '\u007f' || char === '\b') {
65 password = password.slice(0, -1);
66 continue;
67 }
68 password += char;
69 }
70 };
71
72 stdin.on('end', onEnd);
73 stdin.on('data', onData);

Callers

nothing calls this directly

Calls 3

finishFunction · 0.85
cleanupFunction · 0.85
toStringMethod · 0.45

Tested by

no test coverage detected