Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/project/jupyter/test/blobs.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import expect from "expect";67import * as misc_node from "@cocalc/backend/misc_node";89import { blob_store } from "@cocalc/jupyter/blobs";1011describe("very basic tests of the blob store -- ", function () {12const blob_store = get_blob_store();13if (blob_store == null) {14throw Error("blob_store is null");15}1617blob_store.delete_all_blobs();1819it("gets a list of blobs (which should be empty)", () => {20expect(blob_store.keys()).toEqual([]);21});2223// got via24// require('./jupyter').kernel(name:'sage-7.4', verbose:false).execute_code(code:'point((0,0), axes=False, figsize=1)', all:true, cb:(e,m)->console.log(m[2].content.data))25const blob =26"iVBORw0KGgoAAAANSUhEUgAAAFkAAAA4CAYAAACWo1RQAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAAQVJREFUeJzt2iEOwjAcRvEPwuSSSY4AbmbciFNxil0DhYNj4CeGmAAc\nCF7T8H7JkrXqn5emqqt5nufop9alB/gHRgYYGWBkgJEBRgYYGWBkgJEBRgYYGWBkgJEBRgYYGWBk\ngJEBRgYYGWBkgJEBRgYYGWBkwKb0AN+435PTafk/HpOuKzvPp1a1vCCapuRwSC6XZd33yfmcNE3Z\nuT5RTeTbLdnv3/eu12S3KzPPN6q5k7fbpG2f67Zd9mpQTeSuS8YxGYblG0fvZL2o5iTXzMgAIwOM\nDDAywMgAIwOMDDAywMgAIwOMDDAywMgAIwOMDDAywMgAIwOMDDAywMgAIwOMDDAy4AEJciLL9Myg\nZwAAAABJRU5ErkJggg==\n";27const buffer = Buffer.from(blob, "base64");28const sha1 = misc_node.sha1(buffer);2930it("saves a blob", () => {31expect(blob_store.save(blob, "image/png")).toBe(sha1);32expect(blob_store.keys()).toEqual([sha1]);33});3435it("reads a blob", () => {36expect(blob_store.get(sha1)).toEqual(buffer);37});38});394041