io.ts ×12

Frontier kind: Joint frontier

unlabeled · c_d8832e206b89

1 test · 14486 LOC · 65 files · introduces 1 test · 175 LOC · 6 files

Introduces — evidence that enters the hierarchy at this concept

Code
23 ranges175 lines · 6 files
Tests
1 test

Contains — complete concept membership

All code (extent)
2297 ranges14486 lines · 65 files · Browse complete extent
All tests (intent)
1 testBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

1 test introduced at this concept.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

6 files ranked by introduced lines: 175 introduced LOC across 23 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/files/common/io.ts 87 introduced LOC · 12 ranges

Open complete file

28 * A helper to read a file from a provider with open/read/close capability into a stream.
29 */
30 > export async function readFileIntoStream<T>( io.ts
31 > provider: IFileSystemProviderWithOpenReadWriteCloseCapability,
32 > resource: URI,
33 > target: WriteableStream<T>,
34 > transformer: IDataTransformer<VSBuffer, T>,
35 > options: ICreateReadStreamOptions,
36 > token: CancellationToken
37 > ): Promise<void> {
38 > let error: Error | undefined = undefined;
39 >
40 > try {
41 > await doReadFileIntoStream(provider, resource, target, transformer, options, token);
42 > } catch (err) {
43 error = err;
44 > } finally { io.ts
45 > if (error && options.errorTransformer) {
46 error = options.errorTransformer(error);
47 }
48 > io.ts
49 > if (typeof error !== 'undefined') {
50 target.error(error);
51 }
52 > io.ts
53 > target.end();
54 > }
55 > }
56
57 > async function doReadFileIntoStream<T>(provider: IFileSystemProviderWithOpenReadWriteCloseCapability, resource: URI, target: WriteableStream<T>, transformer: IDataTransformer<VSBuffer, T>, options: ICreateReadStreamOptions, token: CancellationToken): Promise<void> { io.ts
58 >
59 > // Check for cancellation
60 > throwIfCancelled(token);
61 >
62 > // open handle through provider
63 > const handle = await provider.open(resource, { create: false });
64 >
65 > try {
66 >
67 > // Check for cancellation
68 > throwIfCancelled(token);
69 >
70 > let totalBytesRead = 0;
71 > let bytesRead = 0;
72 > let allowedRemainingBytes = (options && typeof options.length === 'number') ? options.length : undefined;
73 >
74 > let buffer = VSBuffer.alloc(Math.min(options.bufferSize, typeof allowedRemainingBytes === 'number' ? allowedRemainingBytes : options.bufferSize));
75 >
76 > let posInFile = options && typeof options.position === 'number' ? options.position : 0;
77 > let posInBuffer = 0;
78 > do {
79 > // read from source (handle) at current position (pos) into buffer (buffer) at
80 > // buffer position (posInBuffer) up to the size of the buffer (buffer.byteLength).
81 > bytesRead = await provider.read(handle, posInFile, buffer.buffer, posInBuffer, buffer.byteLength - posInBuffer);
82 >
83 > posInFile += bytesRead;
84 > posInBuffer += bytesRead;
85 > totalBytesRead += bytesRead;
86 >
87 > if (typeof allowedRemainingBytes === 'number') {
88 allowedRemainingBytes -= bytesRead;
89 }
90 > io.ts
91 > // when buffer full, create a new one and emit it through stream
92 > if (posInBuffer === buffer.byteLength) {
93 > await target.write(transformer(buffer));
94 >
95 > buffer = VSBuffer.alloc(Math.min(options.bufferSize, typeof allowedRemainingBytes === 'number' ? allowedRemainingBytes : options.bufferSize));
96 >
97 > posInBuffer = 0;
98 > }
99 > } while (bytesRead > 0 && (typeof allowedRemainingBytes !== 'number' || allowedRemainingBytes > 0) && throwIfCancelled(token) && throwIfTooLarge(totalBytesRead, options));
100 >
101 > // wrap up with last buffer (also respect maxBytes if provided)
102 > if (posInBuffer > 0) {
103 > let lastChunkLength = posInBuffer;
104 > if (typeof allowedRemainingBytes === 'number') {
105 lastChunkLength = Math.min(posInBuffer, allowedRemainingBytes);
106 }
107 > io.ts
108 > target.write(transformer(buffer.slice(0, lastChunkLength)));
109 > }
110 > } catch (error) {
111 throw ensureFileSystemProviderError(error);
112 > } finally { io.ts
113 > await provider.close(handle);
114 > }
115 > }
116
117 > function throwIfCancelled(token: CancellationToken): boolean { io.ts
118 > if (token.isCancellationRequested) {
119 throw canceled();
120 }
121 > io.ts
122 > return true;
123 > }
124
125 > function throwIfTooLarge(totalBytesRead: number, options: ICreateReadStreamOptions): boolean { io.ts
126 >
127 > // Return early if file is too large to load and we have configured limits
128 > if (typeof options?.limits?.size === 'number' && totalBytesRead > options.limits.size) {
129 throw createFileSystemProviderError(localize('fileTooLargeError', "File is too large to open"), FileSystemProviderErrorCode.FileTooLarge);
130 }
131 > io.ts
132 > return true;
133 > }
src/vs/platform/checksum/node/checksumService.ts 30 introduced LOC · 1 range

Open complete file

1 > /*--------------------------------------------------------------------------------------------- checksumService.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { createHash } from 'crypto';
7 > import { listenStream } from '../../../base/common/stream.js';
8 > import { URI } from '../../../base/common/uri.js';
9 > import { IChecksumService } from '../common/checksumService.js';
10 > import { IFileService } from '../../files/common/files.js';
11 >
12 > export class ChecksumService implements IChecksumService {
13 >
14 > declare readonly _serviceBrand: undefined;
15 >
16 > constructor(@IFileService private readonly fileService: IFileService) { }
17 >
18 > async checksum(resource: URI): Promise<string> {
19 > const stream = (await this.fileService.readFileStream(resource)).value;
20 > return new Promise<string>((resolve, reject) => {
21 > const hash = createHash('sha256');
22 >
23 > listenStream(stream, {
24 > onData: data => hash.update(data.buffer),
25 > onError: error => reject(error),
26 > onEnd: () => resolve(hash.digest('base64').replace(/=+$/, ''))
27 > });
28 > });
29 > }
30 > }
src/vs/platform/files/node/diskFileSystemProvider.ts 25 introduced LOC · 4 ranges

Open complete file

232
233 readFileStream(resource: URI, opts: IFileReadStreamOptions, token: CancellationToken): ReadableStreamEvents<Uint8Array> {
234 > const stream = newWriteableStream<Uint8Array>(data => VSBuffer.concat(data.map(data => VSBuffer.wrap(data))).buffer); diskFileSystemProvider.ts
235 >
236 > readFileIntoStream(this, resource, stream, data => data.buffer, {
237 > ...opts,
238 > bufferSize: 256 * 1024 // read into chunks of 256kb each to reduce IPC overhead
239 > }, token);
240 >
241 > return stream;
242 > }
243
244 async writeFile(resource: URI, content: Uint8Array, opts: IFileWriteOptions): Promise<void> {
417 // If `opts.append` is true, use 'a' to append to the file.
418 (opts.append ? 'a' : 'w') :
419 > // Otherwise we assume the file is opened for reading diskFileSystemProvider.ts
420 > // as such we use 'r' to neither truncate, nor create
421 > // the file.
422 > 'r'
423 );
424 }
517
518 async read(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number> {
519 > const normalizedPos = this.normalizePos(fd, pos); diskFileSystemProvider.ts
520 >
521 > let bytesRead: number | null = null;
522 > try {
523 > bytesRead = (await Promises.read(fd, data, offset, length, normalizedPos)).bytesRead;
524 > } catch (error) {
525 throw this.toFileSystemProviderError(error);
526 > } finally { diskFileSystemProvider.ts
527 > this.updatePos(fd, normalizedPos, bytesRead);
528 > }
529 >
530 > return bytesRead;
531 > }
532
533 private normalizePos(fd: number, pos: number): number | null {
src/vs/platform/files/common/fileService.ts 16 introduced LOC · 3 ranges

Open complete file

579
580 async readFileStream(resource: URI, options?: IReadFileStreamOptions, token?: CancellationToken): Promise<IFileStreamContent> {
581 > const provider = await this.withReadProvider(resource); fileService.ts
582 >
583 > return this.doReadFileStream(provider, resource, options, token);
584 > }
585
586 private async doReadFileStream(provider: IFileSystemProviderWithFileReadWriteCapability | IFileSystemProviderWithOpenReadWriteCloseCapability | IFileSystemProviderWithFileReadStreamCapability, resource: URI, options?: IReadFileOptions & IReadFileStreamOptions & { preferUnbuffered?: boolean }, token?: CancellationToken): Promise<IFileStreamContent> {
627 fileStream = this.readFileUnbuffered(provider, resource, readFileOptions);
628 }
630 > // read streamed (always prefer over primitive buffered read)
631 > else if (hasFileReadStreamCapability(provider)) {
632 > fileStream = this.readFileStreamed(provider, resource, cancellableSource.token, readFileOptions);
633 > }
634
635 // read buffered
677
678 private readFileStreamed(provider: IFileSystemProviderWithFileReadStreamCapability, resource: URI, token: CancellationToken, options: IReadFileStreamOptions = Object.create(null)): VSBufferReadableStream {
679 > const fileStream = provider.readFileStream(resource, options, token); fileService.ts
680 >
681 > return transform(fileStream, {
682 > data: data => data instanceof VSBuffer ? data : VSBuffer.wrap(data),
683 > error: error => this.restoreReadError(error, resource, options)
684 > }, data => VSBuffer.concat(data));
685 > }
686
687 private readFileBuffered(provider: IFileSystemProviderWithOpenReadWriteCloseCapability, resource: URI, token: CancellationToken, options: IReadFileStreamOptions = Object.create(null)): VSBufferReadableStream {
src/vs/base/node/pfs.ts 15 introduced LOC · 2 ranges

Open complete file

791
792 get read() {
793 > pfs.ts
794 > // Not using `promisify` here for a reason: the return
795 > // type is not an object as indicated by TypeScript but
796 > // just the bytes read, so we create our own wrapper.
797 >
798 > return (fd: number, buffer: Uint8Array, offset: number, length: number, position: number | null) => {
799 > return new Promise<{ bytesRead: number; buffer: Uint8Array }>((resolve, reject) => {
800 > fs.read(fd, buffer, offset, length, position, (err, bytesRead, buffer) => {
801 > if (err) {
802 return reject(err);
803 }
804 > pfs.ts
805 > return resolve({ bytesRead, buffer });
806 > });
807 > });
808 > };
809 > }
810
811 get write() {
src/vs/platform/files/common/files.ts 2 introduced LOC · 1 range

Open complete file

759
760 export function hasFileReadStreamCapability(provider: IFileSystemProvider): provider is IFileSystemProviderWithFileReadStreamCapability {
761 > return !!(provider.capabilities & FileSystemProviderCapabilities.FileReadStream); files.ts
762 > }
763
764 export interface IFileSystemProviderWithFileAtomicReadCapability extends IFileSystemProvider {