forked from jlongster/absurd-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
4,408 additions
and
780 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,16 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
node: true, | ||
es2021: true, | ||
jest: true | ||
}, | ||
extends: 'eslint:recommended', | ||
parserOptions: { | ||
ecmaVersion: 12, | ||
sourceType: 'module' | ||
}, | ||
rules: { | ||
'no-unused-vars': 'off' | ||
} | ||
}; |
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 |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = {presets: ['@babel/preset-env']} | ||
module.exports = { plugins: ['@babel/plugin-transform-modules-commonjs'] }; |
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,20 @@ | ||
export class IndexedDBBackend { | ||
readChunks(fileName, positions, chunkSize) { | ||
// TODO: | ||
// * Sort positions and find contiguous chunks | ||
// * Run a query for each contiguous chunk | ||
// * Do all this in another syncify worker! | ||
|
||
// return this.syncWorker.readChunks(fileName, positions, chunkSize); | ||
|
||
return []; | ||
} | ||
|
||
writeChunks(writes) { | ||
// Call out to idb (sync!) | ||
|
||
// return this.syncWorker.writeChunks(fileName, positions, chunkSize); | ||
|
||
return []; | ||
} | ||
} |
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,80 @@ | ||
export default class MemoryBackend { | ||
constructor(files, defaultChunkSize) { | ||
this.files = Object.fromEntries( | ||
Object.entries(files).map(([name, data]) => { | ||
return [name, { data, size: data.byteLength }]; | ||
}) | ||
); | ||
this.defaultChunkSize = defaultChunkSize; | ||
} | ||
|
||
getFile(fileName) { | ||
return this.files[fileName]; | ||
} | ||
|
||
getOrCreateFile(fileName) { | ||
if (this.files[fileName] == null) { | ||
this.files[fileName] = { data: new ArrayBuffer(0), size: 0 }; | ||
} | ||
return this.files[fileName]; | ||
} | ||
|
||
deleteFile(fileName) { | ||
this.files[fileName] = null; | ||
} | ||
|
||
readMeta(fileName, defaultMeta) { | ||
let exists = this.getFile(fileName) != null; | ||
let file = this.getOrCreateFile(fileName); | ||
return exists | ||
? { size: file.data.byteLength, chunkSize: this.defaultChunkSize } | ||
: defaultMeta; | ||
} | ||
|
||
writeMeta(fileName, meta) { | ||
let file = this.getOrCreateFile(fileName); | ||
file.size = meta.size; | ||
} | ||
|
||
readChunks(fileName, positions, chunkSize) { | ||
console.log('_reading', fileName, positions); | ||
// if (positions.length > 0) { | ||
// console.log('reading', positions); | ||
// } | ||
let data = this.files[fileName].data; | ||
|
||
return positions.map(pos => { | ||
let buffer = new ArrayBuffer(chunkSize); | ||
|
||
if (pos < data.byteLength) { | ||
new Uint8Array(buffer).set( | ||
new Uint8Array(data, pos, Math.min(chunkSize, data.byteLength - pos)) | ||
); | ||
} | ||
|
||
return { pos, data: buffer }; | ||
}); | ||
} | ||
|
||
writeChunks(fileName, writes) { | ||
console.log('_writing', fileName, writes); | ||
// if (writes.length > 0) { | ||
// console.log('writing', writes.map(w => w.pos)); | ||
// } | ||
let file = this.getOrCreateFile(fileName); | ||
let data = file.data; | ||
|
||
for (let write of writes) { | ||
let fullLength = write.pos + write.data.byteLength; | ||
|
||
if (fullLength > data.byteLength) { | ||
// Resize file | ||
let buffer = new ArrayBuffer(fullLength); | ||
new Uint8Array(buffer).set(new Uint8Array(data)); | ||
this.files[fileName].data = data = buffer; | ||
} | ||
|
||
new Uint8Array(data).set(new Uint8Array(write.data), write.pos); | ||
} | ||
} | ||
} |
Oops, something went wrong.