V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
est
V2EX  ›  Linux

iconv 这个渣渣居然不支持 pipe。。。。文件都读到 buffer 里去了

  •  
  •   est ·
    est · May 6, 2015 · 2723 views
    This topic created in 4015 days ago, the information mentioned may be changed or developed.
    https://sourceware.org/bugzilla/show_bug.cgi?id=6050

    https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=328303

    用stdbuf -o 0 这么伟大的hack都不能拯救这个渣渣。

    zcat myfile | iconv -f gb2312-t UTF-8 | pv > myfifo

    观察了n久,pv一动不动!!!!我2G的文件啊!!!

    于是果断用一行python代替了iconv

    zcat myfile | python -c "for l in __import__('sys').stdin:print l.decode('gb2312', 'ignore').encode('utf8')" | pv > myfifo

    用pv >/dev/null试了下效率,速度为40M/s基本跑到了硬盘瓶颈。
    4 replies    2015-05-14 19:24:47 +08:00
    julyclyde
        1
    julyclyde  
       May 7, 2015
    因为解码算法需要回溯吧?
    est
        2
    est  
    OP
       May 7, 2015
    @julyclyde 那也可以buffer弄小一点啊。。。。。。。16M的buffer足够了吧。。。
    est
        3
    est  
    OP
       May 7, 2015
    想了下,不对啊。为啥python的就可以pipe。。。
    jarlyyn
        4
    jarlyyn  
       May 14, 2015
    iconv最奇葩的是

    nodejs 用pure js实现的iconv-lite库号称比调用iconv的库快
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   825 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 20:13 · PVG 04:13 · LAX 13:13 · JFK 16:13
    ♥ Do have faith in what you're doing.