Socket
Socket
Sign inDemoInstall

code-packer

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    code-packer

这是一个代码打包工具,包含了代码的打包,包读取,执行包内文件的功能。


Version published
Weekly downloads
2
increased by100%
Maintainers
1
Install size
37.4 kB
Created
Weekly downloads
 

Readme

Source

code-packer

这是一个代码打包工具,包含了代码的打包,包读取,执行包内文件的功能。

安装

npm install code-packer

文件打包

import pkg from 'code-packer'

const rootdir = '/path/to/rootdir'

//打包rootdir下的a.js和b.js文件
pkg.pack([rootdir+'/a.js', rootdir+'/b.js'], rootdir)					//无加密打包
pkg.pack([rootdir+'/a.js', rootdir+'/b.js'], rootdir, {password:'123'})	//使用123加密


//直接打包rootdir下的所有文件
pkg.packDir(rootdir)					//不加密
pkg.packDir(rootdir,{password:'123'})	//使用123加密

写入文件

//对打包后的结果使用saveTo函数即可写入

pkg.packDir(rootdir).saveTo('/path/to/file')

读取包

import pkg from 'code-packer'

const p = pkg.load('/path/to/pack')

console.log(p.files)			//文件列表
console.log(p.getFile('a.js'))	//读取a.js文件,得到的时Buffer对象,需自行toString

执行包中的文件

//a.js
module.export = 'Hello world!'

//main.js
import pkg from 'code-packer'
const p = pkg.load('/path/to/pack')
console.log(pkg.run(p, 'a.js'))		//输出: Hello world!

其他说明

如需按自己的规则打包,可使用FilePackage类来创建一个包,并使用其中的方法进行设置。

FAQs

Last updated on 18 Jan 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc