-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#61 added new file.utils.ts for local and remote data reads
- Loading branch information
1 parent
6a0949a
commit d7c8fcb
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as config from '../config'; | ||
import {Logger, LogLevel} from '../logger'; | ||
import {window} from 'vscode'; | ||
|
||
const logger: Logger = new Logger(`file.utils:`, config.logLevel); | ||
|
||
/** | ||
* Reads local data file or fetches public data source data. | ||
* @param dataFilePath Data file path or public data source url. | ||
* @param encoding Data file encoding: 'utf8' for text data files, null for binary data reads. | ||
*/ | ||
export function readDataFile(dataFilePath: string, encoding:string = null): any { | ||
let data: any; | ||
logger.debug('readDataFile(): ', dataFilePath); | ||
if (!dataFilePath.startsWith('http://') && !dataFilePath.startsWith('https://')) { | ||
// read local data file via fs read file api | ||
// TODO: change this to read data async later | ||
data = fs.readFileSync(dataFilePath, encoding); | ||
} else { | ||
// TODO: fetch remote data with https://github.com/d3/d3-fetch | ||
data = ''; | ||
} | ||
return data; | ||
} |