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

btof

v1.0.0

Published

简单使用的Base64转文件或文件(图像)转base64的包

Downloads

13

Readme

Base64_to_File

简单粗暴的Base64转文件及逆向转换(文件到Base64)包, 不依赖任何第三方包支持, 纯原生Node语法编写, MIT开源, 随意折腾. 本包为后端专用, 不适用于前端使用(浏览器), 请知悉!

如何使用

  1. npm安装这个依赖包在当前项目中
  2. 导入这个包
  3. new一个新的Base64对象即可使用相关API

举个例子

包目录下有一个 demo.js 文件, 如果无法理解的, 可以直接运行这个文件即可!

// 引入包
const Base64 = require("base64");
// new一个新的Base64的类出来
let base64 = new Base64();
// 使用相关API(以下代码仅供理解,不等于可以直接运行)
base64.fileToBase64('demo.jpg');
base64.base64ToFile('data:image/png,Base64,....','demo.jpg');

相关API

  1. Base64.fileToBase64(filePath,opts)
    • 文件转Base64
    • 参数部分:
      • filePath
        • 文件路径
        • 数据类型: String
      • opts
        • 可配置项, 可留空, 留空使用默认值
        • 数据类型: Object
        • 相关配置节点
          • async
            • 是否异步读取(默认false,即同步读取直接return出结果)
            • 数据类型: Boolean
          • callback
            • 异步读取的回调函数
            • 参数
              • base64编码
            • 数据类型: Function
          • prefix
            • 是否开启前缀
            • 前缀就是 data:image/png,base64,巴拉巴拉啥的
            • 默认: true
            • 数据类型: Boolean
          • ext
            • 是否指定后缀<格式>
            • 默认: false
            • 如果指定了后缀, 且开启前缀的情况下, data:image/这里,base64 的格式将会被设置成你指定的格式, 而不是自动识别出来的格式
            • 数据类型: Boolean
  2. Base64.base64ToFile(base64,filePath,opts)
    • base64转文件
    • 参数部分:
      • base64
        • base64编码
        • 无需处理前缀,会自动处理
        • 处理方式是通过逗号分割,[0]=前缀, [1]=编码部分
        • 数据类型: String
      • filePath
        • 存储路径
        • 数据类型: String
      • opts
        • 可配置项, 可留空
        • 数据类型: Object
        • 相关配置节点
          • async
            • 是否异步写入(默认false,即同步写入)
            • 数据类型: Boolean
          • callback
            • 异步读取的回调函数
            • 参数参考Nodejs原生fs.writeFile方法回调参数
            • 数据类型: Function
  3. Base64.ftob()
    • 等于 Base64.fileToBase64(filePath,opts)
    • 换句话来说就是他的简写形式
  4. Base64.btof()
    • 等于 Base64.base64ToFile(base64,filePath,opts)
    • 换句话来说就是他的简写形式