From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8f01d35116e753b6 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.236.170 with SMTP id uv10mr13622381pbc.4.1332885732632; Tue, 27 Mar 2012 15:02:12 -0700 (PDT) Path: z9ni8976pbe.0!nntp.google.com!news2.google.com!goblin1!goblin2!goblin.stu.neva.ru!news.internetdienste.de!news.tu-darmstadt.de!news.belwue.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Wed, 28 Mar 2012 00:01:49 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20120313 Thunderbird/11.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: xor References: <9t8mq9Fla4U1@mid.individual.net> <9t99r9F6e2U1@mid.individual.net> In-Reply-To: Message-ID: <4f7238ce$0$6643$9b4e6d93@newsspool2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 28 Mar 2012 00:01:50 CEST NNTP-Posting-Host: 11e526ef.newsspool2.arcor-online.net X-Trace: DXC=7;1T`CWKPj_HigV@eW57PQA9EHlD;3YcR4Fo<]lROoRQ8kFejVXg 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;