1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

test node-xz

This commit is contained in:
Matthias Kretschmann 2020-09-24 16:34:42 +02:00
parent 7188f33707
commit ca19be4390
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 26 additions and 21 deletions

32
package-lock.json generated
View File

@ -1458,12 +1458,6 @@
"@types/node": "*"
}
},
"@types/lz-string": {
"version": "1.3.34",
"resolved": "https://registry.npmjs.org/@types/lz-string/-/lz-string-1.3.34.tgz",
"integrity": "sha512-j6G1e8DULJx3ONf6NdR5JiR2ZY3K3PaaqiEuKYkLQO0Czfi1AzrtjfnfCROyWGeDd5IVMKCwsgSmMip9OWijow==",
"dev": true
},
"@types/mocha": {
"version": "8.0.3",
"resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-8.0.3.tgz",
@ -6643,11 +6637,6 @@
"integrity": "sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==",
"dev": true
},
"lz-string": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz",
"integrity": "sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY="
},
"macos-release": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/macos-release/-/macos-release-2.4.1.tgz",
@ -10341,9 +10330,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=="
}
}
},
@ -11884,6 +11873,21 @@
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="
},
"xz": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/xz/-/xz-2.0.2.tgz",
"integrity": "sha512-K0rWxVLh2yRuvM0alMiwzxkkygUZcrJ8pNZ0JT0yTGoZ0FyqwHnY6Mbt7BcATP9abMVeCpiEqmear2ixHZSaLQ==",
"requires": {
"node-addon-api": "^1.6.1"
},
"dependencies": {
"node-addon-api": {
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.2.tgz",
"integrity": "sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg=="
}
}
},
"y18n": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz",

View File

@ -45,19 +45,18 @@
"@oceanprotocol/contracts": "^0.4.4",
"decimal.js": "^10.2.0",
"fs": "0.0.1-security",
"lz-string": "^1.4.4",
"node-fetch": "^2.6.1",
"save-file": "^2.3.1",
"uuid": "^8.3.0",
"web3": "^1.3.0",
"web3-eth-contract": "^1.3.0"
"web3-eth-contract": "^1.3.0",
"xz": "^2.0.2"
},
"devDependencies": {
"@release-it/bumper": "^2.0.0",
"@truffle/hdwallet-provider": "^1.0.37",
"@types/chai": "^4.2.11",
"@types/chai-spies": "^1.0.1",
"@types/lz-string": "^1.3.34",
"@types/mocha": "^8.0.3",
"@types/node": "^14.6.4",
"@types/node-fetch": "^2.5.5",

View File

@ -5,7 +5,7 @@ import { AbiItem } from 'web3-utils/types'
import Web3 from 'web3'
import defaultDDOContractABI from '@oceanprotocol/contracts/artifacts/Metadata.json'
import { didZeroX } from '../utils'
import lz from 'lz-string'
import { Compressor } from 'xz'
/**
* Provides an interface with Metadata Store.
@ -35,12 +35,14 @@ export class OnChainMetadataStore {
}
/**
* Compress DDO using lz-string
* Compress DDO using xz/lzma2
*/
public async compressDDO(ddo: DDO): Promise<string> {
const data = DDO.serialize(ddo)
const compressed = lz.compress(data)
return this.getHex(compressed)
const buffer = Buffer.from(data)
const compression = new Compressor({ preset: 9 })
const compressed = await compression.updatePromise(buffer)
return this.getHex(compressed.toString())
}
/**