惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
博客园 - 叶小钗
爱范儿
爱范儿
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
阮一峰的网络日志
阮一峰的网络日志
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
美团技术团队
T
Tailwind CSS Blog
博客园 - 司徒正美
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
宝玉的分享
宝玉的分享
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
人人都是产品经理
人人都是产品经理
小众软件
小众软件
博客园 - 【当耐特】
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - CarlZeng

NetSuite接口开发之JSON源数据发送实现gzip压缩 硬件PCB设计及编程实现学习项目pixl-js-模拟Amiibo wordpress转支付宝小程序 奥克掌机更换霍尔摇杆及校准 DSE-Shoulder-R1-L1-and-Bumper-R2-L2-Omoron-Switch-Buttons ESXI之N5105倍控小主机体验及现实应用 如何远程编译生成Switch最新版大气层整合包 自建远程协助软件rustdesk实现远程桌面远程控制软件 浅谈路由器Openwrt防火墙的-端口转发-与-NAT穿透-区别与优缺点 Joycon2手柄如何连接电脑测试按键摇杆等功能 Switch大气层游戏下载服务及实测列表 塞尔达传说王国之泪公主之花模组MOD XBOX精英二代霍尔板机故障修复及校准 Switch大气层20-整合包1-9-0测试版 - CarlZeng How-to-extract-text-from-PDF-Image-files-OCR-CarlZeng How-to-setup-oAuth-2-0-in-NetSuite-RESTlet-API-如何在NetSuite中设置RESTlet-API的oAuth2-0认证 吉比特光猫HG6145D1改桥接获超级密码开Telnet Nintendo-Switch安装塞尔达传说Mod大师模式 光猫设置端口映射IP端口转发 Switch安装安卓系统用于调试硬件 Switch联网证书浅谈 Switch下安装全能模拟器switch全能模拟器RetroArch Docker搭建pigallery2目录优先的图片库网站 ffmpeg拼接摄像头录制的MP4文件 Switch大气层20-整合包1-9-0测试版 索尼PlayStation全部记录
NetSuite的gzip解压缩在接口开发中的应用
CarlZeng · 2026-08-06 · via 博客园 - CarlZeng

NetSuite的gzip解压缩在接口开发中的应用, 常见于接口开发中大数据量的传输, 用gzip压缩和解压缩功能提供传输效率

Your browser does not support the audio element.

有什么用

可以看到NetSuite的gzip解压缩在接口开发中的应用

接口改造

接口优化

怎么用

两端的开发人员协调, 将不同系统中数据传输, 在接口端 和 主发送端口 将数据进行解压缩和压缩工作,

从而达到: 提高数据传输速率, 减少数据传输量, 另个角度加密数据; 对大量数据传输的情形有显著的效果提升作用

相关内容

NetSuite实现方法

NetSuite的SuiteScript在2023年加入的 N/compress Module模块, 实现了服务端对数据进行压缩和解压缩的buildin支持.

NetSuite发送往第三方系统

将NS中的数据/报表, 通过JSON组织成string字符串的类型, 然后compress.gzip进行压缩(压缩级别可选: 1-9),

最后通过payload把数据post到第三方系统的接口节点上. NS端实例如下:

....
var objTxtFile = file.create({
    fileType: 'PLAINTEXT',
    name: 'file.txt',
    encoding: file.Encoding.UTF8,
    contents: JSON.stringify(arrInvUpdateData)
});
var gzippedFile = compress.gzip({
    file: objTxtFile,
    level: 4
});
var strGzipText = gzippedFile.getContents();

let objBody = {
    "messageId": new Date().getTime().toString(),
    "route": "goodsInventoryUpdate",
    "payload":  strGzipText
};

...

第三方系统发到NetSuite接口

从第三方系统发送到NetSuite的接口; RESTlet; NetSuite端对接收的数据进行解压缩; 然后处理相应的业务需求

var objTxtFile = file.create({
                fileType: file.Type.GZIP,
                name: 'zipped.txt.gz',
                encoding: file.Encoding.UTF8,
                folder: -15,
                contents: strBodyZipped
            });

            var guzippedFile = compress.gunzip({
                file: objTxtFile
            });

            var strGuzipText = guzippedFile.getContents();
            strGuzipText = strGuzipText.toString().replaceAll('\\', '');
            strGuzipText = strGuzipText.substr(1, strGuzipText.length-2);

            requestBodyOrg.body = JSON.parse(strGuzipText);

需要注意的点有:

  1. Netuite的compress.gunzip接收的参数是文件的类型
  2. compress.gunzip接收的文件类型需要必须是.gz, GZIP的文件类型: file.Type.GZIP
    1. 这点很重要, 虽然内部是相同的内容, 如果是txt文件, NetSuite会解压缩报错
  3. 解压缩以后的字符串, 是第三方系统处理过的, 需要进行一些清洗清洁工作, 比如 \ 和多余的 ""

其他第三方gzip解决方案

多文件的压缩与解压缩

使用 JSZip-Sync

JSZip-Sync is a Javascript library created for creating, reading and editing .zip files in a simple way.
JSZip is a javascript library for creating, reading and editing .zip files, with a lovely and simple API.

使用步骤:

  • 下载 jszip.min.js file; the npm site.
  • 上传到NetSuite script 文件夹
  • 添加模块定义 define object ('./jszip.min.js')

举例解压缩一个zip文件

....
const getZipContents = (fileId) => {
    try {
        if(fileId){
            /** zip文件已存放于filecabinet中 */
            let objZippedFile = file.load({
                id: fileId
            })
            let strZippedFileContents = objZippedFile.getContents()
            let arrUnzippedFiles = [];

            var new_zip = new JSZip();

            new_zip.sync(function () {
                let zip = new_zip.loadAsync(strZippedFileContents, {base64:true})._result;
                /** 压缩包中遍历每个文件 */
                Object.keys(zip.files).forEach(fileName => {
                   
                    let strFileContent = zip.file(fileName).async("string");.

                    arrUnzippedFiles.push({
                        file_name: fileName,
                        file_contents: strFileContent._result
                    })
                })
            })
            return arrUnzippedFiles;
        }
  } catch(error){
       log.error ('解压缩失败文件id ' + intZipFileId, error)
  }
}
....
....

const zippedFile = file.load({id: fileId});
            const zippedFileContent = zippedFile.getContents();
            const unzippedFiles = [];

            const ZipInstance = new jszip();

            ZipInstance.sync(function () {
                ZipInstance.loadAsync(zippedFileContent, {base64: true}).then(function (zip) {
                    Object.keys(zip.files).forEach(function(filename){
                        const file =  zip.file(filename).async("string");

                        unzippedFiles.push({
                            name: filename,
                            content: file._result,
                            size: file._result.length
                        })

                    });
                })
            });
....