mirror of https://github.com/status-im/metro.git
Use a single file delimited with null characters
Reviewed By: rafeca Differential Revision: D7232425 fbshipit-source-id: c51387b94cd990ed3ba9be5c82b14c2a7773c7e7
This commit is contained in:
parent
601f718dd6
commit
cf5a431388
|
@ -20,6 +20,9 @@ export type Options = {|
|
||||||
root: string,
|
root: string,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
|
const JOINER_DATA = '\0\0';
|
||||||
|
const JOINER_LIST = '\0';
|
||||||
|
|
||||||
class FileStore {
|
class FileStore {
|
||||||
_root: string;
|
_root: string;
|
||||||
|
|
||||||
|
@ -35,7 +38,14 @@ class FileStore {
|
||||||
|
|
||||||
get(key: Buffer): ?TransformedCode {
|
get(key: Buffer): ?TransformedCode {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(fs.readFileSync(this._getFilePath(key), 'utf-8'));
|
const data = fs.readFileSync(this._getFilePath(key), 'utf8');
|
||||||
|
const [code, dependencies, map] = data.split(JOINER_DATA);
|
||||||
|
|
||||||
|
return {
|
||||||
|
code,
|
||||||
|
dependencies: dependencies ? dependencies.split(JOINER_LIST) : [],
|
||||||
|
map: JSON.parse(map),
|
||||||
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code === 'ENOENT') {
|
if (err.code === 'ENOENT') {
|
||||||
return null;
|
return null;
|
||||||
|
@ -46,7 +56,13 @@ class FileStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
set(key: Buffer, value: TransformedCode): void {
|
set(key: Buffer, value: TransformedCode): void {
|
||||||
fs.writeFileSync(this._getFilePath(key), JSON.stringify(value));
|
const data = [
|
||||||
|
value.code,
|
||||||
|
value.dependencies.join(JOINER_LIST),
|
||||||
|
JSON.stringify(value.map),
|
||||||
|
].join(JOINER_DATA);
|
||||||
|
|
||||||
|
fs.writeFileSync(this._getFilePath(key), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
_getFilePath(key: Buffer): string {
|
_getFilePath(key: Buffer): string {
|
||||||
|
|
Loading…
Reference in New Issue