[33170] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4449 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 12 03:09:18 2015

Date: Fri, 12 Jun 2015 00:09:03 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 12 Jun 2015     Volume: 11 Number: 4449

Today's topics:
        Want to readout the control file of aria2. <hongyi.zhao@gmail.com>
    Re: Want to readout the control file of aria2. <gamo@telecable.es>
    Re: Want to readout the control file of aria2. <hongyi.zhao@gmail.com>
    Re: Want to readout the control file of aria2. <justin.1503@purestblue.com>
    Re: Want to readout the control file of aria2. <rweikusat@mobileactivedefense.com>
    Re: Want to readout the control file of aria2. <hongyi.zhao@gmail.com>
    Re: Want to readout the control file of aria2. <rweikusat@mobileactivedefense.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 9 Jun 2015 22:20:55 +0000 (UTC)
From: Hongyi Zhao <hongyi.zhao@gmail.com>
Subject: Want to readout the control file of aria2.
Message-Id: <ml7os7$aog$1@aspen.stu.neva.ru>

Hi all,

I want to read out the control file of aria2, which is a binary file 
including the data format depicted here:

http://aria2.sourceforge.net/manual/en/html/technical-notes.html

Could you please give me some snipped codes for this purpose?

Regards
-- 
 .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.


------------------------------

Date: Wed, 10 Jun 2015 10:33:52 +0200
From: gamo <gamo@telecable.es>
Subject: Re: Want to readout the control file of aria2.
Message-Id: <ml8spp$tla$1@speranza.aioe.org>

El 10/06/15 a las 00:20, Hongyi Zhao escribió:
> Hi all,
>
> I want to read out the control file of aria2, which is a binary file
> including the data format depicted here:
>
> http://aria2.sourceforge.net/manual/en/html/technical-notes.html
>
> Could you please give me some snipped codes for this purpose?
>
> Regards
>

Try something like:

open IN, "<", "example.aria2" or die "$!";
read IN, $one, 2;
read IN, $two, 4;
close IN;

It's supposed that that variables $one and $two hold
the first bytes of the file.
For more information: perldoc -f read

-- 
http://www.telecable.es/personales/gamo/
The generation of random numbers is too important to be left to chance


------------------------------

Date: Wed, 10 Jun 2015 09:00:29 +0000 (UTC)
From: Hongyi Zhao <hongyi.zhao@gmail.com>
Subject: Re: Want to readout the control file of aria2.
Message-Id: <ml8ubc$dcf$1@aspen.stu.neva.ru>

On Wed, 10 Jun 2015 10:33:52 +0200, gamo wrote:

> Try something like:
> 
> open IN, "<", "example.aria2" or die "$!";
> read IN, $one, 2;
> read IN, $two, 4;
> close IN;
> 
> It's supposed that that variables $one and $two hold the first bytes of
> the file.
> For more information: perldoc -f read

Thanks a lot for your hints.

Regards
-- 
 .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.


------------------------------

Date: Wed, 10 Jun 2015 10:04:09 +0100
From: Justin C <justin.1503@purestblue.com>
Subject: Re: Want to readout the control file of aria2.
Message-Id: <95bl4c-k66.ln1@eddie.masonsmusic.co.uk>

On 2015-06-09, Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
> Hi all,
>
> I want to read out the control file of aria2, which is a binary file 
> including the data format depicted here:
>
> http://aria2.sourceforge.net/manual/en/html/technical-notes.html
>
> Could you please give me some snipped codes for this purpose?

We don't write code to order here. We help solve problems with code
you've written. Show us your attempt and we'll help you debug it.

   Justin.

-- 
Justin C, by the sea.


------------------------------

Date: Wed, 10 Jun 2015 14:53:23 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Want to readout the control file of aria2.
Message-Id: <87mw07isa4.fsf@doppelsaurus.mobileactivedefense.com>

gamo <gamo@telecable.es> writes:
> El 10/06/15 a las 00:20, Hongyi Zhao escribió:
>> Hi all,
>>
>> I want to read out the control file of aria2, which is a binary file
>> including the data format depicted here:
>>
>> http://aria2.sourceforge.net/manual/en/html/technical-notes.html
>>
>> Could you please give me some snipped codes for this purpose?
>>
>> Regards
>>
>
> Try something like:
>
> open IN, "<", "example.aria2" or die "$!";
> read IN, $one, 2;
> read IN, $two, 4;
> close IN;
>
> It's supposed that that variables $one and $two hold
> the first bytes of the file.
> For more information: perldoc -f read

Another option would be to read the complete file into a scalar (untested),

my $data;
{
	local $/;
        $data = <IN>;
}

and take it apart with unpack. For a 'version 1' file (which has a
defined byte order), this could be done with (also untested for want of
an example file)

my ($ver, $x0, $x1, $x2, $x3, $hlen) = unpack('nC4N', $data)

would retrieve the version, the four extension bytes and the hash
length. unpack can work with offets but stripping away the processed
parts from the data is IMHO easier (perl can do this efficiently),

substr($data, 0, 10, '');

would get rid of the header. The hash could then be retrieved and
removed with

my $hash = substr($data, 0, $hlen, '');

and the remainder of the input processed in a similar way.




------------------------------

Date: Wed, 10 Jun 2015 23:06:09 +0000 (UTC)
From: Hongyi Zhao <hongyi.zhao@gmail.com>
Subject: Re: Want to readout the control file of aria2.
Message-Id: <mlaft0$rs1$1@aspen.stu.neva.ru>

On Wed, 10 Jun 2015 14:53:23 +0100, Rainer Weikusat wrote:
[...]
> (also untested for want of an example file)

Thanks a lot, I posted a example file here:

http://share.weiyun.com/ebc3c26f1fd64be4f8c8acecd6aca0d1

Regards
-- 
 .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.


------------------------------

Date: Thu, 11 Jun 2015 16:07:41 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Want to readout the control file of aria2.
Message-Id: <87lhfqwaf6.fsf@doppelsaurus.mobileactivedefense.com>

Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> On Wed, 10 Jun 2015 14:53:23 +0100, Rainer Weikusat wrote:
> [...]
>> (also untested for want of an example file)
>
> Thanks a lot, I posted a example file here:
>
> http://share.weiyun.com/ebc3c26f1fd64be4f8c8acecd6aca0d1

This is not a particularly interesting or difficult problem and also a
rather ill-defined one as nobody knows what you want to do with the
information. I think you're better of using unpack than read because
unpack not only takes the input apart but also turns it into
ready-to-use Perl data. It should be reasonably straight-forward to
write the code based on the pack/ unpack documentation and the examples
posted. Since there are a lot of fields in this file format and Perl
doesn't really support data structures, creating a class which takes the
input as argument, breaks it down into its parts and stores it
somewhere, providing access to said parts via methods would IMHO be a
good idea (but if you only want to do something very simple, it might be
overkill to create something that general).

I suggest that you just start with something and possibly come back with
more specific question in case you get stuck.





------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 4449
***************************************


home help back first fref pref prev next nref lref last post