mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge pull request #311 from oceanprotocol/fix/lzma
replace lzma library
This commit is contained in:
commit
f5e7014477
6
package-lock.json
generated
6
package-lock.json
generated
@ -10335,9 +10335,9 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": {
|
||||
"version": "12.12.59",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.59.tgz",
|
||||
"integrity": "sha512-D2MISWfv2j17aFBAkMD3lQ97vYpXCkAJMJf0mx2eKHNkzXA6Vo9w7A7BWi9fH8sOH1zeFb7fIhOo22z0TtrSag=="
|
||||
"version": "12.12.62",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.62.tgz",
|
||||
"integrity": "sha512-qAfo81CsD7yQIM9mVyh6B/U47li5g7cfpVQEDMfQeF8pSZVwzbhwU3crc0qG4DmpsebpJPR49AKOExQyJ05Cpg=="
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -5,7 +5,10 @@ import { AbiItem } from 'web3-utils/types'
|
||||
import Web3 from 'web3'
|
||||
import defaultDDOContractABI from '@oceanprotocol/contracts/artifacts/Metadata.json'
|
||||
import { didZeroX } from '../utils'
|
||||
import { LZMA } from 'lzma'
|
||||
|
||||
// Using limited, compress-only version
|
||||
// See https://github.com/LZMA-JS/LZMA-JS#but-i-dont-want-to-use-web-workers
|
||||
import { LZMA } from 'lzma/src/lzma-c'
|
||||
|
||||
/**
|
||||
* Provides an interface with Metadata Store.
|
||||
@ -34,17 +37,16 @@ export class OnChainMetadataStore {
|
||||
)
|
||||
}
|
||||
|
||||
/** Compress DDO using LZMA
|
||||
*
|
||||
/**
|
||||
* Compress DDO using xz/lzma2
|
||||
*/
|
||||
public async LZMACompressDDO(ddo: DDO): Promise<any> {
|
||||
|
||||
public async compressDDO(ddo: DDO): Promise<string> {
|
||||
const data = DDO.serialize(ddo)
|
||||
const lzma = new LZMA()
|
||||
// see https://github.com/LZMA-JS/LZMA-JS/issues/44
|
||||
lzma.disableEndMark = true
|
||||
let compressed = lzma.compress(data, 9)
|
||||
compressed = this.getHex(compressed)
|
||||
return compressed
|
||||
LZMA.disableEndMark = true
|
||||
const compressed = LZMA.compress(data, 9)
|
||||
return this.getHex(compressed)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,7 +62,7 @@ export class OnChainMetadataStore {
|
||||
consumerAccount: string
|
||||
): Promise<TransactionReceipt> {
|
||||
let flags = 0
|
||||
const compressed = await this.LZMACompressDDO(ddo)
|
||||
const compressed = await this.compressDDO(ddo)
|
||||
flags = flags | 1
|
||||
return this.publishRaw(didZeroX(did), flags, compressed, consumerAccount)
|
||||
}
|
||||
@ -78,7 +80,7 @@ export class OnChainMetadataStore {
|
||||
consumerAccount: string
|
||||
): Promise<TransactionReceipt> {
|
||||
let flags = 0
|
||||
const compressed = await this.LZMACompressDDO(ddo)
|
||||
const compressed = await this.compressDDO(ddo)
|
||||
flags = flags | 1
|
||||
return this.updateRaw(didZeroX(did), flags, compressed, consumerAccount)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user