remove broken import

This commit is contained in:
Florent Beauchamp
2024-02-09 16:07:24 +00:00
parent 1e0c411d5f
commit b3e163d090

View File

@@ -13,8 +13,8 @@ const {
} = require('./_constants') } = require('./_constants')
const { fuHeader, checksumStruct } = require('./_structs') const { fuHeader, checksumStruct } = require('./_structs')
const assert = require('node:assert') const assert = require('node:assert')
const { NBD_DEFAULT_BLOCK_SIZE } = require('@vates/nbd-client/constants.mjs')
const NBD_DEFAULT_BLOCK_SIZE = 64 * 1024
const MAX_DURATION_BETWEEN_PROGRESS_EMIT = 5e3 const MAX_DURATION_BETWEEN_PROGRESS_EMIT = 5e3
const MIN_TRESHOLD_PERCENT_BETWEEN_PROGRESS_EMIT = 1 const MIN_TRESHOLD_PERCENT_BETWEEN_PROGRESS_EMIT = 1
@@ -35,34 +35,32 @@ exports.createNbdRawStream = function createRawStream(nbdClient) {
return stream return stream
} }
function batContainsBlock(bat, blockId) {
function batContainsBlock(bat, blockId){
const entry = bat.readUInt32BE(blockId * 4) const entry = bat.readUInt32BE(blockId * 4)
if(entry !== BLOCK_UNUSED){ if (entry !== BLOCK_UNUSED) {
return [{blockId, size: DEFAULT_BLOCK_SIZE} ] return [{ blockId, size: DEFAULT_BLOCK_SIZE }]
} }
} }
// one 2MB VHD block is in 32 blocks of 64KB // one 2MB VHD block is in 32 blocks of 64KB
// 32 bits are written in 8 4bytes uint32 // 32 bits are written in 8 4bytes uint32
const EMPTY_NBD_BUFFER = Buffer.alloc(NBD_DEFAULT_BLOCK_SIZE, 0) const EMPTY_NBD_BUFFER = Buffer.alloc(NBD_DEFAULT_BLOCK_SIZE, 0)
function cbtContainsBlock(cbt, blockId){ function cbtContainsBlock(cbt, blockId) {
let subBlocks = [] const subBlocks = []
let hasOne = false let hasOne = false
for(let i=0; i < 32; i ++){ for (let i = 0; i < 32; i++) {
let position = blockId * 32 + i const position = blockId * 32 + i
const bitOffset = position & 7; // in byte const bitOffset = position & 7 // in byte
const byteIndex = position >> 3; // in buffer const byteIndex = position >> 3 // in buffer
const bit = (buffer[byteIndex] >> bitOffset) & 1; const bit = (cbt[byteIndex] >> bitOffset) & 1
if(bit ===1){ if (bit === 1) {
subBlocks.push({blockId: position, size: NBD_DEFAULT_BLOCK_SIZE}) subBlocks.push({ blockId: position, size: NBD_DEFAULT_BLOCK_SIZE })
hasOne = true hasOne = true
} else { } else {
// don't read empty blocks // don't read empty blocks
subBlocks.push({buffer:EMPTY_NBD_BUFFER }) subBlocks.push({ buffer: EMPTY_NBD_BUFFER })
} }
} }
if(hasOne){ if (hasOne) {
return subBlocks return subBlocks
} }
} }
@@ -85,7 +83,7 @@ exports.createNbdVhdStream = async function createVhdStream(
// new table offset // new table offset
header.tableOffset = FOOTER_SIZE + HEADER_SIZE header.tableOffset = FOOTER_SIZE + HEADER_SIZE
let streamBat let streamBat
if(changedBlocks === undefined){ if (changedBlocks === undefined) {
streamBat = await readChunkStrict(sourceStream, batSize) streamBat = await readChunkStrict(sourceStream, batSize)
} }
let offset = FOOTER_SIZE + HEADER_SIZE + batSize let offset = FOOTER_SIZE + HEADER_SIZE + batSize
@@ -119,7 +117,7 @@ exports.createNbdVhdStream = async function createVhdStream(
const subBlocks = changedBlocks ? cbtContainsBlock(changedBlocks, blockId) : batContainsBlock(streamBat, blockId) const subBlocks = changedBlocks ? cbtContainsBlock(changedBlocks, blockId) : batContainsBlock(streamBat, blockId)
if (subBlocks !== undefined) { if (subBlocks !== undefined) {
bat.writeUInt32BE(offsetSector, blockId * 4) bat.writeUInt32BE(offsetSector, blockId * 4)
entries.push({blockId, subBlocks}) entries.push({ blockId, subBlocks })
offsetSector += blockSizeInSectors offsetSector += blockSizeInSectors
} else { } else {
bat.writeUInt32BE(BLOCK_UNUSED, blockId * 4) bat.writeUInt32BE(BLOCK_UNUSED, blockId * 4)
@@ -173,8 +171,8 @@ exports.createNbdVhdStream = async function createVhdStream(
// yield blocks from nbd // yield blocks from nbd
const nbdIterator = nbdClient.readBlocks(function* () { const nbdIterator = nbdClient.readBlocks(function* () {
for (const {subBlocks} of entries) { for (const { subBlocks } of entries) {
for(const {blockId, buffer, size} of subBlocks){ for (const { blockId, buffer, size } of subBlocks) {
yield { index: blockId, buffer, size } yield { index: blockId, buffer, size }
} }
} }