Golang: bytes.Buffer 缓冲区大小超过最大限制

huangapple go评论95阅读模式
英文:

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.jsjquery.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

huangapple
  • 本文由 发表于 2015年3月9日 13:08:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/28935577.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定