@commonlyai/cli 0.1.177 → 0.1.178
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -11,6 +11,8 @@ import { isAbsolute, relative, sep } from 'path';
|
|
|
11
11
|
// material across arbitrary stream chunk boundaries before any model sees it.
|
|
12
12
|
export const redactProviderMaterial = (material) => {
|
|
13
13
|
const secret = Buffer.from(material);
|
|
14
|
+
// An empty key matches everywhere and the scan below would never advance.
|
|
15
|
+
if (secret.length === 0) throw new TypeError('provider material to redact is empty');
|
|
14
16
|
let pending = Buffer.alloc(0);
|
|
15
17
|
return new Transform({
|
|
16
18
|
transform(chunk, _encoding, done) {
|
|
@@ -25,6 +27,13 @@ export const redactProviderMaterial = (material) => {
|
|
|
25
27
|
this.push(pending.subarray(0, count)); pending = pending.subarray(count);
|
|
26
28
|
}
|
|
27
29
|
}
|
|
30
|
+
// Hold back only the longest tail that could still start the key, so a
|
|
31
|
+
// streamed token is not delayed until a key's length of bytes follows it.
|
|
32
|
+
let keep = Math.min(pending.length, secret.length - 1);
|
|
33
|
+
while (keep > 0 && !pending.subarray(pending.length - keep).equals(secret.subarray(0, keep))) keep -= 1;
|
|
34
|
+
if (pending.length > keep) {
|
|
35
|
+
this.push(pending.subarray(0, pending.length - keep)); pending = pending.subarray(pending.length - keep);
|
|
36
|
+
}
|
|
28
37
|
done();
|
|
29
38
|
},
|
|
30
39
|
flush(done) { this.push(pending); pending = Buffer.alloc(0); done(); },
|