英文:
Golang: bytes.Buffer max buffer exceeded
问题
我正在尝试使用minify库来捆绑和压缩所有的JavaScript和CSS代码,最小化的代码如下:
js := bytes.Buffer{}
dat, err := ioutil.ReadFile(fname)
if L.Check(err, `文件不存在:`+fname) == nil {
dat, err = min.MinifyBytes(`text/js`, dat)
js.Write(dat)
js.WriteRune(';')
}
但是当对ace.js和jquery.dataTables.js(大小超过400 KB)进行压缩时,该代码出现了err="max buffer exceeded"
的错误。这是bytes.Buffer
的问题吗?如何解决这个问题?
英文:
I'm trying to use minify library to bundle and minify all my JavaScripts and CSSs, minimum code:
js := bytes.Buffer{}
dat, err := ioutil.ReadFile(fname)
if L.Check(err, `File doesn't exists: `+fname) == nil {
dat, err = min.MinifyBytes(`text/js`, dat)
js.Write(dat)
js.WriteRune(';')
}
But that code failed with err="max buffer exceeded"
when minifying ace.js and jquery.dataTables.js (>400 KB) is this bytes.Buffer
problem? and how to fix this?
答案1
得分: 2
根据GoDoc.org的说明,该错误实际上是由该作者的另一个包parse
引发的。
文档注释表示输入的大小不能超过4KB。您的库似乎比这大得多。
幸运的是,MaxBuf
变量是从该包中导出的,所以您可以在该代码之前添加以下行来修复_特定的错误_:
parse.MaxBuf = parse.MaxBuf * 2
英文:
According to GoDoc.org, that error is actually thrown from another package by that author .. parse
.
The doc comment says that the input cannot be larger than 4KB in size. Your libraries appear to be much bigger than that.
Luckily, the MaxBuf
variable is exported from that package .. so you should be able to put this line before that code to fix that particular error:
parse.MaxBuf = parse.MaxBuf * 2
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论