-
Notifications
You must be signed in to change notification settings - Fork 276
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
1 parent
85f6079
commit 1ad7d03
Showing
25 changed files
with
495 additions
and
710 deletions.
There are no files selected for viewing
File renamed without changes.
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
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
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
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
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
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,63 @@ | ||
import { DiskBlock, RandomAccessDisk } from "./Disk.mjs"; | ||
import { FileAccessor } from "./FileAccessor.mjs"; | ||
|
||
|
||
export class RawDisk extends RandomAccessDisk{ | ||
#accessor | ||
#path | ||
#descriptor:number|undefined | ||
#blockSize:number | ||
#size: number|undefined | ||
|
||
|
||
constructor(accessor: FileAccessor, path: string, blockSize:number){ | ||
super() | ||
this.#accessor= accessor | ||
this.#path = path | ||
this.#blockSize = blockSize | ||
} | ||
async readBlock(index: number): Promise<DiskBlock> { | ||
if(this.#descriptor === undefined){ | ||
throw new Error("Can't call readBlock before init"); | ||
} | ||
const data = Buffer.alloc(this.getBlockSize(), 0) | ||
await this.#accessor.read(this.#descriptor, data, index*this.getBlockSize()) | ||
return { | ||
index, | ||
data | ||
} | ||
} | ||
getVirtualSize(): number { | ||
if(this.#size === undefined){ | ||
throw new Error("Can't call getVirtualsize before init"); | ||
} | ||
return this.#size | ||
} | ||
getBlockSize(): number { | ||
return this.#blockSize | ||
} | ||
async init(): Promise<void> { | ||
this.#descriptor = await this.#accessor.open(this.#path) | ||
this.#size = await this.#accessor.getSize(this.#path) | ||
} | ||
async close(): Promise<void> { | ||
this.#descriptor && await this.#accessor.close(this.#descriptor) | ||
this.#descriptor = undefined | ||
this.#size = undefined | ||
} | ||
isDifferencing(): boolean { | ||
return false | ||
} | ||
getBlockIndexes(): Array<number> { | ||
const nbBlocks = Math.ceil(this.getVirtualSize()/ this.getBlockSize()) | ||
const index =[] | ||
for(let i=0; i < nbBlocks; i ++){ | ||
index.push(i) | ||
} | ||
return index | ||
} | ||
hasBlock(index: number): boolean { | ||
return index * this.getBlockSize() < this.getVirtualSize() | ||
} | ||
|
||
} |
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,29 @@ | ||
import {DiskPassthrough} from './DiskPassthrough.mjs' | ||
import {Synchronized} from '@vates/generator-toolbox' | ||
import {Disk, DiskBlock} from './Disk.mjs' | ||
|
||
export class SynchronizedDisk extends DiskPassthrough{ | ||
#synchronized:Synchronized<DiskBlock, any,any> |undefined | ||
#source:Disk | ||
constructor(source:Disk){ | ||
super() | ||
this.#source = source | ||
} | ||
async openSource():Promise<Disk>{ | ||
// await this.#source.init() | ||
this.#synchronized = new Synchronized(await this.#source.buildDiskBlockGenerator()) | ||
return this.#source | ||
} | ||
async * diskBlocks(uid:string): AsyncGenerator<DiskBlock>{ | ||
console.log('will fork') | ||
if(this.#synchronized === undefined){ | ||
throw new Error("Can't cann fork before init") | ||
} | ||
return this.#synchronized.fork(uid) | ||
} | ||
|
||
async close(){ | ||
console.log('SynchronizedDisk.close') | ||
await this.source.close() // this will trigger cleanup in syncrhonized | ||
} | ||
} |
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
File renamed without changes.
Oops, something went wrong.