Skip to content

Commit

Permalink
feat: speed up manifest sync (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomicvladan authored Jan 29, 2024
1 parent 081b4ea commit 90fc2d0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/command/manifest/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { readFileSync } from 'fs'
import { Argument, LeafCommand, Option } from 'furious-commander'
import { Reference } from 'mantaray-js'
import { join } from 'path'
import { makeChunkedFile } from '@fairdatasociety/bmt-js'
import { pickStamp } from '../../service/stamp'
import { readdirDeepAsync } from '../../utils'
import { BzzAddress } from '../../utils/bzz-address'
import { stampProperties } from '../../utils/option'
import { ManifestCommand } from './manifest-command'
import { bytesToHex } from '../../utils/hex'

export class Sync extends ManifestCommand implements LeafCommand {
public readonly name = 'sync'
Expand Down Expand Up @@ -48,11 +50,13 @@ export class Sync extends ManifestCommand implements LeafCommand {
continue
}

const remoteData = await this.bee.downloadData(Buffer.from(fork.node.getEntry).toString('hex'))
const remoteAddress = Buffer.from(fork.node.getEntry).toString('hex')

const localData = readFileSync(join(this.folder, file))
const rootChunk = makeChunkedFile(localData).rootChunk()
const localAddress = bytesToHex(rootChunk.address())

// TODO make this more efficient once the chunker is available
if (localData.equals(remoteData)) {
if (localAddress === remoteAddress) {
this.console.log('ok -> ' + file)
} else {
const { reference } = await this.bee.uploadData(this.stamp, readFileSync(join(this.folder, file)))
Expand Down

0 comments on commit 90fc2d0

Please sign in to comment.