fix(angular): support large buffers in angular cli adapter (#15082)

This commit is contained in:
Leosvel Pérez Espinosa 2023-02-17 15:17:29 +00:00 committed by GitHub
parent 861bad90d8
commit a1a1cdaf4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -0,0 +1,11 @@
import { arrayBufferToString } from './ngcli-adapter';
describe('ngcli-adapter', () => {
it('arrayBufferToString should support large buffers', () => {
const largeString = 'a'.repeat(1000000);
const result = arrayBufferToString(Buffer.from(largeString));
expect(result).toBe(largeString);
});
});

View File

@ -388,8 +388,19 @@ export class NxScopedHost extends virtualFs.ScopedHost<any> {
}
}
function arrayBufferToString(buffer: any) {
return String.fromCharCode.apply(null, new Uint8Array(buffer));
export function arrayBufferToString(buffer: any) {
const array = new Uint8Array(buffer);
let result = '';
const chunkSize = 8 * 1024;
let i = 0;
for (i = 0; i < array.length / chunkSize; i++) {
result += String.fromCharCode.apply(
null,
array.subarray(i * chunkSize, (i + 1) * chunkSize)
);
}
result += String.fromCharCode.apply(null, array.subarray(i * chunkSize));
return result;
}
export class NxScopeHostUsedForWrappedSchematics extends NxScopedHost {