Skip to content
Snippets Groups Projects
Commit b90480cb authored by Alexander Rose's avatar Alexander Rose
Browse files

sync/await for file reading

parent 858e6640
No related branches found
No related tags found
No related merge requests found
...@@ -42,7 +42,8 @@ ...@@ -42,7 +42,8 @@
"ts-jest": "^21.1.2", "ts-jest": "^21.1.2",
"tslint": "^5.7.0", "tslint": "^5.7.0",
"typescript": "^2.5.3", "typescript": "^2.5.3",
"uglify-js": "^3.1.3" "uglify-js": "^3.1.3",
"util.promisify": "^1.0.0"
}, },
"dependencies": {} "dependencies": {}
} }
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
import * as util from 'util' import * as util from 'util'
import * as fs from 'fs' import * as fs from 'fs'
require('util.promisify').shim();
const readFileAsync = util.promisify(fs.readFile);
import Gro from './reader/gro/parser' import Gro from './reader/gro/parser'
import CIF from './reader/cif/index' import CIF from './reader/cif/index'
...@@ -76,13 +79,9 @@ async function runGro(input: string) { ...@@ -76,13 +79,9 @@ async function runGro(input: string) {
console.log(residueNumber.length, residueNumber[0], residueNumber[residueNumber.length - 1]) console.log(residueNumber.length, residueNumber[0], residueNumber[residueNumber.length - 1])
} }
export function _gro() { export async function _gro() {
fs.readFile(`./examples/${file}`, 'utf8', function (err, input) { const input = await readFileAsync(`./examples/${file}`, 'utf8')
if (err) { runGro(input)
return console.log(err);
}
runGro(input)
});
} }
// _gro() // _gro()
...@@ -110,30 +109,22 @@ async function runCIF(input: string | Uint8Array) { ...@@ -110,30 +109,22 @@ async function runCIF(input: string | Uint8Array) {
console.log(mmcif.pdbx_struct_oper_list.matrix.value(0)); console.log(mmcif.pdbx_struct_oper_list.matrix.value(0));
} }
export function _cif() { export async function _cif() {
let path = `./examples/1cbs_updated.cif`; let path = `./examples/1cbs_updated.cif`;
path = '../test/3j3q.cif' // lets have a relative path for big test files path = '../test/3j3q.cif' // lets have a relative path for big test files
fs.readFile(path, 'utf8', function (err, input) { const input = await readFileAsync(path, 'utf8')
if (err) { console.log('------------------');
return console.log(err); console.log('Text CIF:');
} runCIF(input);
console.log('------------------');
console.log('Text CIF:');
runCIF(input);
});
path = `./examples/1cbs_full.bcif`; path = `./examples/1cbs_full.bcif`;
// const path = 'c:/test/quick/3j3q.cif'; // const path = 'c:/test/quick/3j3q.cif';
fs.readFile(path, function (err, input) { const input2 = await readFileAsync(path)
if (err) { console.log('------------------');
return console.log(err); console.log('BinaryCIF:');
} const data = new Uint8Array(input2.byteLength);
console.log('------------------'); for (let i = 0; i < input2.byteLength; i++) data[i] = input2[i];
console.log('BinaryCIF:'); runCIF(input2);
const data = new Uint8Array(input.byteLength);
for (let i = 0; i < input.byteLength; i++) data[i] = input[i];
runCIF(input);
});
} }
// _cif(); // _cif();
...@@ -155,16 +146,12 @@ async function runDic(input: string | Uint8Array) { ...@@ -155,16 +146,12 @@ async function runDic(input: string | Uint8Array) {
// console.log(util.inspect(Object.keys(schema).length, {showHidden: false, depth: 1})) // console.log(util.inspect(Object.keys(schema).length, {showHidden: false, depth: 1}))
} }
export function _dic() { export async function _dic() {
let path = './build/dics/mmcif_pdbx_v50.dic' let path = './build/dics/mmcif_pdbx_v50.dic'
fs.readFile(path, 'utf8', function (err, input) { const input = await readFileAsync(path, 'utf8')
if (err) { console.log('------------------');
return console.log(err); console.log('Text DIC:');
} runDic(input);
console.log('------------------');
console.log('Text DIC:');
runDic(input);
});
} }
_dic(); _dic();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment