From b739ade285b2ab6f18765fc53a5295c25a62030b Mon Sep 17 00:00:00 2001 From: Robert burner Schadek Date: Thu, 17 Mar 2016 01:00:54 +0100 Subject: [PATCH] no more stream!? --- source/dyaml/streamcompat.d | 62 ---------------------------------- source/dyaml/testcommon.d | 4 +-- source/dyaml/testinputoutput.d | 1 + 3 files changed, 3 insertions(+), 64 deletions(-) delete mode 100644 source/dyaml/streamcompat.d diff --git a/source/dyaml/streamcompat.d b/source/dyaml/streamcompat.d deleted file mode 100644 index fa035fd..0000000 --- a/source/dyaml/streamcompat.d +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright Ferdinand Majerech 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -/// Backward compatibility with std.stream (which was used by D:YAML API in the past). -module dyaml.streamcompat; - - -import std.stream; - -import tinyendian; - - -/// A streamToBytes wrapper that allocates memory using the GC. -/// -/// See_Also: streamToBytes -ubyte[] streamToBytesGC(Stream stream) @trusted nothrow -{ - try return stream.streamToBytes(new ubyte[stream.available]); - catch(Exception e) - { - assert(false, "Unexpected exception in streamToBytesGC: " ~ e.msg); - } -} - -/// Read all data from a Stream into an array of bytes. -/// -/// Params: -/// -/// stream = Stream to read from. Must be readable and seekable. -/// memory = Memory to use. Must be long enough to store the entire stream -/// (memory.length >= stream.available). -/// -/// Returns: A slice of memory containing all contents of the stream on success. -/// NULL if unable to read the entire stream. -ubyte[] streamToBytes(Stream stream, ubyte[] memory) @system nothrow -{ - try - { - assert(stream.readable && stream.seekable, - "Can't read YAML from a stream that is not readable and seekable"); - assert(memory.length >= stream.available, - "Not enough memory passed to streamToBytes"); - - auto buffer = memory[0 .. stream.available]; - size_t bytesRead = 0; - for(; bytesRead < buffer.length;) - { - // Returns 0 on eof - const bytes = stream.readBlock(&buffer[bytesRead], buffer.length - bytesRead); - // Reached EOF before reading buffer.length bytes. - if(bytes == 0) { return null; } - bytesRead += bytes; - } - return buffer; - } - catch(Exception e) - { - assert(false, "Unexpected exception in streamToBytes " ~ e.msg); - } -} diff --git a/source/dyaml/testcommon.d b/source/dyaml/testcommon.d index 57e0b19..61e5c67 100644 --- a/source/dyaml/testcommon.d +++ b/source/dyaml/testcommon.d @@ -11,7 +11,7 @@ version(unittest) public import std.conv; public import std.stdio; -public import std.stream; +//public import std.stream; public import dyaml.all; import core.exception; @@ -24,7 +24,7 @@ import std.typecons; package: -alias std.stream.File File; +//alias std.stream.File File; /** * Run an unittest. diff --git a/source/dyaml/testinputoutput.d b/source/dyaml/testinputoutput.d index c16aa28..1c3427e 100644 --- a/source/dyaml/testinputoutput.d +++ b/source/dyaml/testinputoutput.d @@ -15,6 +15,7 @@ import std.file; import std.system; import dyaml.testcommon; +import dyaml.stream; alias std.system.endian endian;