@ssc-hermes/public-blobs
TypeScript icon, indicating that this package has built-in type declarations

0.1.7 • Public • Published

public blobs tests

Write content addressed blobs to cloudinary, using a blake3 hash algorithm.

example

write a file

Write a base64 encoded blob to cloudinary, get a hash in response.

import dotenv from 'dotenv'
import { test } from 'tapzero'
import { Blobs } from '@ssc-hermes/public-blobs'
import { v2 } from 'cloudinary'
dotenv.config()
const cloudinary = v2

const config = {
    cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
    api_key: process.env.CLOUDINARY_API_KEY,
    api_secret: process.env.CLOUDINARY_API_SECRET
}

const base64file = 'data:image/png;base64,...'
cloudinary.config(config)

let blobs
test('create a cloudinary', async t => {
    blobs = Blobs(cloudinary)
    t.ok(blobs, 'blobs exists')
})

test('blobs.write', async t => {
    // `hash` is a url-safe string
    const { hash } = await blobs.write(base64file)

    t.ok(hash, 'hash exists')
    t.equal(hash, 'QyATP2PuM7EajnUt0IQlc5eRNsjQePxl9E_5YLpNGR0',
        'should return the expected hash')
})

get a file

Then use @cloudinary/url-gen to get the file by hash:

import { scale } from "@cloudinary/url-gen/actions/resize"
import { Cloudinary } from '@cloudinary/url-gen'

const cld = new Cloudinary({
    cloud: { cloudName: 'test' },
    url: {
        secure: true // force https, set to false to force http
    }
})

const url = cld
    .image(hash)
    .resize( scale().width(100) )
    .toURL()

Readme

Keywords

none

Package Sidebar

Install

npm i @ssc-hermes/public-blobs

Weekly Downloads

0

Version

0.1.7

License

AGPL-3.0-or-later

Unpacked Size

16 kB

Total Files

19

Last publish

Collaborators

  • nichoth