npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

icp-create-server

v1.0.0

Published

Starting from redbean.com, replace the content of the index.html file inside it with something else

Downloads

3

Readme

Interactive Code Playgrounds - Create Server

Hacky solution to set up a single-file distributable server based on redbean for the Interactive Code Playgrounds project. Given the redbean.com file returned from the build step of icp-bundle and the HTML code for some Reveal.js slides, icp-create-server generates a new redbean.com file updated with the given content. A normal ZIP handling library can't be used, since we need to modify in-place redbean.com without recreating it from scratch. A better solution would be to create a complete library for managing ZIP files working directly on hex level, but for the scope of this project this is enough.

Get started

🐇 Quick start

Install icp-create-server with your packet manager:

npm install icp-create-server

Then import the generateRedbeanFile function:

import { generateRedbeanFile } from 'icp-create-server'

// Slides to put into redbean
const slides = "<section><h1>Hello world!</h1></section>";

// Get the redbean.com file returned from the build of icp-bundle
const response = await fetch(redbeanUrl);
const file = await response.blob();

// Get the hex string
let zipString = bufferToHex(await file.arrayBuffer());

// Call generateRedbeanFile
const generated: Uint8Array = await generateRedbeanFile(
    slides, zipString
);

where bufferToHex is a simple function like:

function bufferToHex(buffer) {
    return [...new Uint8Array(buffer)]
        .map((b) => b.toString(16).padStart(2, "0"))
        .join("");
}

❓ How it works

Understanding the ZIP file format is the key. More information about it can be found in:

When changing the content of a file inside a ZIP, the most important things to consider are:

  • re-calculating the CRC-32 value;
  • re-calculating the uncompressed and compressed sizes (in our case, they will be the same);
  • re-calculating the offset to start of central directory header.

❗ Important note

redbean.com is a customized version of the original one. This version can be built from the icp-bundle repository.