How to use the borc.Decoder function in borc

To help you get started, we’ve selected a few borc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ipld / js-ipld-dag-cbor / src / util.js View on Github external
}
    if (options.tags) {
      tags = Object.assign({}, defaultTags, options && options.tags)
    }
  } else {
    // no options, reset to defaults
    currentSize = defaultSize
    maxSize = defaultMaxSize
  }

  const decoderOptions = {
    tags: tags,
    size: currentSize
  }

  decoder = new cbor.Decoder(decoderOptions)
  // borc edits opts.size in-place so we can capture _actual_ size
  currentSize = decoderOptions.size
}
github zbo14 / constellate / lib / dag-cbor.js View on Github external
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.

*/

const codec = 'dag-cbor'
const version = 1

const CID_CBOR_TAG = 42

const decoder = new cbor.Decoder({
    tags: {
        [CID_CBOR_TAG]: val => {
            return {
                '/': val.slice(1)
            }
        }
    }
})

const serialize = (elem, tasks, t, i) => {
    const seen = []
    let cid
    const tagged = transform(elem, val => {
        if (!isObject(val)) {
            return val
        }
github zbo14 / constellate / src / dag-cbor.js View on Github external
The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.

*/

const CID_CBOR_TAG = 42

const decoder = new cbor.Decoder({
  tags: {
    [CID_CBOR_TAG]: val => {
      return {
        '/': val.slice(1)
      }
    }
  }
})

const sha2_256 = data => {
  return crypto.createHash('sha256').update(data).digest()
}

exports.codec = 'dag-cbor'
exports.version = 1

borc

Encode and parse data in the Concise Binary Object Representation (CBOR) data format (RFC7049).

MIT
Latest version published 4 years ago

Package Health Score

56 / 100
Full package analysis