1- import * as child_process from 'child_process' ;
21import * as cpp from 'child-process-promise' ;
2+ import * as child_process from 'child_process' ;
33import * as fs from 'fs-extra' ;
44import * as path from 'path' ;
55import * as sarif from 'sarif' ;
6+ import { Readable } from 'stream' ;
7+ import { StringDecoder } from 'string_decoder' ;
68import * as tk from 'tree-kill' ;
79import * as util from 'util' ;
8- import { SortDirection , QueryMetadata } from './interface-types' ;
9- import { Logger , ProgressReporter } from './logging' ;
10- import { Disposable , CancellationToken } from 'vscode' ;
10+ import { CancellationToken , Disposable } from 'vscode' ;
11+ import { BQRSInfo , DecodedBqrsChunk } from "./bqrs-cli-types" ;
1112import { DistributionProvider } from './distribution' ;
1213import { assertNever } from './helpers-pure' ;
13- import { Readable } from 'stream ' ;
14- import { StringDecoder } from 'string_decoder ' ;
14+ import { QueryMetadata , SortDirection } from './interface-types ' ;
15+ import { Logger , ProgressReporter } from './logging ' ;
1516
1617/**
1718 * The version of the SARIF format that we are using.
@@ -461,6 +462,7 @@ export class CodeQLCliServer implements Disposable {
461462 * Gets the RAM setting for the query server.
462463 * @param queryMemoryMb The maximum amount of RAM to use, in MB.
463464 * Leave `undefined` for CodeQL to choose a limit based on the available system memory.
465+ * @param progressReporter The progress reporter to send progress information to.
464466 * @returns String arguments that can be passed to the CodeQL query server,
465467 * indicating how to split the given RAM limit between heap and off-heap memory.
466468 */
@@ -471,6 +473,38 @@ export class CodeQLCliServer implements Disposable {
471473 }
472474 return await this . runJsonCodeQlCliCommand < string [ ] > ( [ 'resolve' , 'ram' ] , args , "Resolving RAM settings" , progressReporter ) ;
473475 }
476+ /**
477+ * Gets the headers (and optionally pagination info) of a bqrs.
478+ * @param bqrsPath The path to the bqrs.
479+ * @param pageSize The page size to precompute offsets into the binary file for.
480+ */
481+ async bqrsInfo ( bqrsPath : string , pageSize ?: number ) : Promise < BQRSInfo > {
482+ const subcommandArgs = (
483+ pageSize ? [ "--paginate-rows" , pageSize . toString ( ) ] : [ ]
484+ ) . concat (
485+ bqrsPath
486+ ) ;
487+ return await this . runJsonCodeQlCliCommand < BQRSInfo > ( [ 'bqrs' , 'info' ] , subcommandArgs , "Reading bqrs header" ) ;
488+ }
489+
490+ /**
491+ * Gets the results from a bqrs.
492+ * @param bqrsPath The path to the bqrs.
493+ * @param resultSet The result set to get.
494+ * @param pageSize How many results to get.
495+ * @param offset The 0-based index of the first result to get.
496+ */
497+ async bqrsDecode ( bqrsPath : string , resultSet : string , pageSize ?: number , offset ?: number ) : Promise < DecodedBqrsChunk > {
498+ const subcommandArgs = [
499+ "--entities=url,string" ,
500+ "--result-set" , resultSet ,
501+ ] . concat (
502+ pageSize ? [ "--rows" , pageSize . toString ( ) ] : [ ]
503+ ) . concat (
504+ offset ? [ "--start-at" , offset . toString ( ) ] : [ ]
505+ ) . concat ( [ bqrsPath ] ) ;
506+ return await this . runJsonCodeQlCliCommand < DecodedBqrsChunk > ( [ 'bqrs' , 'decode' ] , subcommandArgs , "Reading bqrs data" ) ;
507+ }
474508
475509
476510 async interpretBqrs ( metadata : { kind : string , id : string } , resultsPath : string , interpretedResultsPath : string , sourceInfo ?: SourceInfo ) : Promise < sarif . Log > {
0 commit comments