comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: xor
Date: Wed, 28 Mar 2012 00:01:49 +0200
Date: 2012-03-28T00:01:50+02:00	[thread overview]
Message-ID: <4f7238ce$0$6643$9b4e6d93@newsspool2.arcor-online.net> (raw)
In-Reply-To: <Pine.GSO.4.64.1203272218010.2980@kodiak1>

On 27.03.12 23:44, Michael Moeller wrote:
> dealing with ciphers
> the size of file is well known in advance and must be verified in any event.
> In addition sometimes we'll only pick certain parts of a pretty huge file
> and we never hit EOF.


Just in case you'll have to read blocks, and while Ada.Streams
should be most efficient, another convenient and also venerable
method uses an instance Direct_IO, instantiated for blocks.
You can set the file position to the block you need.

with Ada.Direct_IO;
with Interfaces;

procedure Position is

    -- Read "xyz.bin", second block, where
    -- $ perl -e "print 'x' x 512, 'y' x 512, 'z' x 512" > xyz.bin

    subtype Byte is Interfaces.Unsigned_8;

    type Block_Index is range 0 .. 511;
    type Block is array (Block_Index) of Byte;

    package Block_IO is new Ada.Direct_IO (Block);

    -- second block should be all 'y's; in terms of Byte:
    Y : constant Byte := Byte'Val (Character'Pos ('y'));

    -- a virtual character not occuring in input:
    Rubbish: constant Byte := Byte'Val (Character'Pos ('*'));

    Input : Block_IO.File_Type;
    Data : Block := Block'(Block_Index => Rubbish);

    use Block_IO;
begin
    Open (Input, Name => "xyz.bin", Mode => In_File);
    Set_Index (Input, To => 2);
    Read (Input, Item => Data);
    Close (Input);

    if Data /= Block'(Block_Index => Y) then
       raise Program_Error;
    end if;
end Position;




  reply	other threads:[~2012-03-27 22:02 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-25 14:28 xor Michael Moeller
2012-03-25 14:01 ` xor Niklas Holsti
2012-03-25 15:16   ` xor Michael Moeller
2012-03-25 19:05     ` xor Dmitry A. Kazakov
2012-03-27 20:31       ` xor Michael Moeller
2012-03-25 19:26     ` xor Niklas Holsti
2012-03-27 20:09       ` xor Michael Moeller
2012-03-27 19:44         ` xor Dmitry A. Kazakov
2012-03-27 21:16           ` xor Michael Moeller
2012-03-27 21:14             ` xor Simon Wright
2012-03-27 22:56               ` xor Michael Moeller
2012-03-27 22:03             ` xor Georg Bauhaus
2012-03-27 23:50               ` xor Michael Moeller
     [not found]                 ` <bbedne9wdofZyu_SnZ2dnUVZ_hydnZ2d@earthlink.com>
2012-03-28 12:18                   ` xor Michael Moeller
2012-03-28 12:48                     ` xor Georg Bauhaus
2012-03-28 15:23                       ` xor Michael Moeller
2012-03-28 15:58                         ` xor Niklas Holsti
2012-03-28 17:28                           ` xor Michael Moeller
2012-03-28 23:25                           ` xor Randy Brukardt
2012-03-29  5:17                             ` xor Niklas Holsti
2012-03-29 23:41                               ` xor Randy Brukardt
2012-03-30 21:53                                 ` xor Niklas Holsti
     [not found]                         ` <jtmdnfjWWsUYoO7SnZ2dnUVZ_gSdnZ2d@earthlink.com>
2012-03-28 17:44                           ` xor Michael Moeller
2012-03-28 14:07                     ` xor Dmitry A. Kazakov
2012-03-28 16:16                       ` xor Michael Moeller
2012-03-28 16:08                         ` xor Dmitry A. Kazakov
2012-03-28 17:36                           ` xor Michael Moeller
     [not found]                             ` <tdadna1MV6uj5O7SnZ2dnUVZ_jidnZ2d@earthlink.com>
2012-03-28 21:48                               ` xor Georg Bauhaus
2012-03-29  7:43                               ` xor Dmitry A. Kazakov
2012-03-29  7:49                               ` xor Simon Wright
2012-03-27 21:28           ` xor Georg Bauhaus
2012-03-27 19:50         ` xor Randy Brukardt
2012-03-27 21:44           ` xor Michael Moeller
2012-03-27 22:01             ` Georg Bauhaus [this message]
2012-03-27 20:13         ` xor Jeffrey Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox