Coder Social home page Coder Social logo

goiria's Introduction

CircleCI codecov

goIria

Goによる分割ダウンロード実装

Features

  • Rangeアクセスを用いる
  • いくつかのゴルーチンでダウンロードしてマージする
  • エラー処理を工夫する
  • golang.org/x/sync/errgourpパッケージなどを使ってみる
  • キャンセルが発生した場合の実装を行う

How to use

$ go get github.com/yusukemisa/goIria

$ go install github.com/yusukemisa/goIria

$ goIria https://dl.google.com/go/go1.10.1.src.tar.gz

分割ダウンロード方針

  • Headリクエストでファイルサイズを調べる
  • Headリクエストのタイムアウトを設定する(5秒)
  • 取得ファイルがrangeに対応してない場合は終了
  • CPUコア数で分割リクエストするときのrangeヘッダ付与時に指定するサイズを計算する
  • リクエストヘッダにrangeを付加してgoルーチンでリクエスト→取得した塊を一時ファイルに保存
  • 取得したファイルを合体して復元する
  • 分割ダウンロード中のgorutineでエラーが発生した時はerrgourpを使用する

分割ダウンロードのUT

  • とりあえず1ケース
  • Circle CIで自動実行
  • カバレッジの測定
  • 失敗するパティーンの作成

curlでやる場合

$ curl -I -r 0-50 https://beauty.hotpepper.jp/CSP/c_common/ALL/IMG/cam_cm_327_98.jpg
HTTP/1.1 206 Partial Content
Date: Sun, 29 Apr 2018 08:33:45 GMT
Server: Apache
Set-Cookie: GalileoCookie=WuWDaawaLscAAGyE-x8AAADl; path=/; expires=Thu, 26-Apr-29 08:33:45 GMT
Last-Modified: Fri, 20 Apr 2018 02:26:42 GMT
ETag: "d1a9074-13eb0-56a3e6b2a3c80"
Accept-Ranges: bytes
Content-Length: 51
P3P: CP="NON DSP COR CURa ADMa DEVa TAIa PSDo OUR BUS UNI COM NAV STA"
Content-Range: bytes 0-50/81584
Content-Type: image/jpeg

goiria's People

Contributors

yusukemisa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.