PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Download resume with NET::HTTP
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Download resume with NET::HTTP

Réponse
 
LinkBack Outils de la discussion
Vieux 09/05/2008, 15h18   #1
Alex Dj
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Download resume with NET::HTTP

I'm wondering is there any way to do interrupt file download and then
resume it from the same spot?
The way I download file:

Net::HTTP.start("server.com") { |http|
response = http.request_get('/some/path') {|response|
file_length = response['Content-Length']
File.open('video.avi', 'w') {|f|
response.read_body do |str| # read body now
puts str.length
f.write str
end
}
}
}

I'm not using open-url as I found that open() method first downloads
whole file and then starts to write it. Not for me....

Cheers Alex
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 09/05/2008, 16h03   #2
Marcelo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Download resume with NET::HTTP

On Fri, May 9, 2008 at 8:18 AM, Alex Dj <djioev@gmail.com> wrote:

> Net::HTTP.start("server.com") { |http|
> response = http.request_get('/some/path') {|response|


create your request by hand:

req = Net::HTTP::Get.new(path)
req.range = ...

In HTTP 1.1 range has the form "[lower]-[upper]", so "[lower]-" is
valid. I'm not sure what range= takes, you get to try it :-)

Marcelo

  Réponse avec citation
Vieux 09/05/2008, 16h34   #3
Alex Dj
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Download resume with NET::HTTP

Thanks Marcelo,

> In HTTP 1.1 range has the form "[lower]-[upper]", so "[lower]-" is
> valid. I'm not sure what range= takes, you get to try it :-)


I found that its "Range: bytes=10000-", something like this. I wonder if
I can use this header to download the same file from different mirrors
i.e. have several
req = Net::HTTP::Get.new(path)
but with different ranges and write them to the same file with random
access. Would it be a right technique for this idea?

Thanks Alex

--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h23.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08035 seconds with 11 queries