<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    JUST DO IT ~

    我只想當個程序員

    為什么 open-uri 有時候是stringio 有時候返回 tmpfile?

    為什么 open-uri 有時候是stringio 有時候返回 tmpfile?
    我用ruby openuri 慢.
    1.網絡io文件大小未定,作為類庫的設計者. 
      小文件太多,不好.IO性能差.
      單個文件太大,如果都用memorybuffer,內存占用會非常的大.
      設計者考慮2邊的靈活性.
    2.我實際使用為什么會慢.因為網絡慢,丟包厲害.調整這個參數確實沒什么用.
    在irb中調用
    require 'open-uri'
    zipfile = open("https://www.baidu.com/img/bdlogo.png")
    require 'open-uri'
    # Don't allow downloaded files to be created as StringIO. Force a tempfile to be created.
    OpenURI::Buffer.send :remove_const, 'StringMax' if OpenURI::Buffer.const_defined?('StringMax')
    OpenURI::Buffer.const_set 'StringMax', 2000000
    irb(main):010:0> zipfile = open("https://www.baidu.com/img/bdlogo.png")
    => #<Tempfile:/var/folders/ss/kfvmx1195cj_zz3zb3tg0ch00000gn/T/open-uri20150617-13110-yt0suh>
    修改配置后測試 
    require 'open-uri'
    # Don't allow downloaded files to be created as StringIO. Force a tempfile to be created.
    OpenURI::Buffer.send :remove_const, 'StringMax' if OpenURI::Buffer.const_defined?('StringMax')
    OpenURI::Buffer.const_set 'StringMax', 0
    irb(main):004:0> zipfile = open("https://www.baidu.com/img/bdlogo.png")
    => #<StringIO:0x007fe2f9008b68 @base_uri=#<URI::HTTPS https://www.baidu.com/img/
    參考: 
    http://stackoverflow.com/questions/10496874/why-does-openuri-treat-files-under-10kb-in-size-as-stringio
    When one does network programming, you allocate a buffer of a reasonably large size and send and read units of data which will fit in the buffer. However, when dealing with files (or sometimes things called BLOBs) you cannot assume that the data will fit into your buffer. So, you need special handling for these large streams of data.
    (Sometimes the units of data which fit into the buffer are called packets. However, packets are really a layer 4 thing, like frames are at layer 2. Since this is happening a layer 7, they might better be called messages.)
    For replies larger than 10K, the open-uri library is setting up the extra overhead to write to a stream objects. When under the StringMax size, it just includes the string in the message, since it knows it can fit in the buffer.

    posted on 2015-06-17 21:12 小高 閱讀(293) 評論(0)  編輯  收藏 所屬分類: Ruby on Rails

    導航

    <2015年6月>
    31123456
    78910111213
    14151617181920
    21222324252627
    2829301234
    567891011

    統計

    常用鏈接

    留言簿(3)

    隨筆分類(352)

    收藏夾(19)

    關注的blog

    手冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产最新凸凹视频免费| 成人无遮挡裸免费视频在线观看| 国产一区二区三区免费在线观看| 在线亚洲高清揄拍自拍一品区| 最好看的中文字幕2019免费| 久久亚洲AV成人无码电影| 91青青国产在线观看免费| 亚洲综合视频在线观看| 免费黄色福利视频| 亚洲w码欧洲s码免费| 成人人免费夜夜视频观看| 久久综合亚洲色hezyo| 免费精品国产自产拍观看| 久久国产美女免费观看精品| 亚洲欧洲美洲无码精品VA| 高清一区二区三区免费视频| 久久精品亚洲一区二区| 美女内射毛片在线看免费人动物| 亚洲首页在线观看| 好男人www免费高清视频在线| 亚洲另类无码专区丝袜| 亚洲裸男gv网站| 日本免费久久久久久久网站| 亚洲日韩乱码久久久久久| 妞干网在线免费观看| 无码的免费不卡毛片视频| 久久久久久亚洲精品| 久久精品女人天堂AV免费观看| 羞羞视频免费网站入口| 亚洲一区二区三区无码中文字幕| 亚洲电影在线免费观看| 亚洲精品国产精品| 狠狠色伊人亚洲综合成人| 日韩亚洲国产高清免费视频| 粉色视频成年免费人15次| 亚洲AV无码专区在线播放中文 | 不卡视频免费在线观看| 亚洲最新永久在线观看| 国产青草视频在线观看免费影院| 成人免费一区二区三区| 亚洲а∨天堂久久精品9966|