Comments (16)
We're now at 64%, progress!
from byte-stream.
I'd be happy to work on this one!
from byte-stream.
Just submit a PR. :-)
from byte-stream.
I'm having trouble while testing the ZlibOutputStream
.
Here are my steps:
-
I create a
IteratorStream
with thefixtures/foobar.txt
contents, like in theZlibInputStreamTest
. -
In the
ZlibOutputStream
instance I don't know what to pass as to the first parameter. What kind ofOutputStream
should I use? I tried to use anew ResourceOutputStream(fopen("php://memory", "wb+"))
. I also tried to create aResourceInputStream
with the same resource stream, but I can't read it back. -
I'm writing the contents of the
IteratorStream
to theZlibOutputStream
. -
Now I need to assert that the contents of the
OutputStream
instance matchfixtures/foobar.txt.gz
. I know I can't read from that interface, but I'm not sure how to proceed. Maybe astream_socket_pair
like in theResourceStreamTest
?
from byte-stream.
I guess we could add an OutputBuffer
that implements Promise
and OutputStream
and resolves the promise once the stream has ended or fails it if there's an error.
Would you be interested in working on that?
Another solution is to use a stream pair, as you suggested.
from byte-stream.
Yes absolutely. In my mind this would complement the InMemoryStream
.
from byte-stream.
I don't have a really good grasp of the Amp framework, so I'm not sure I can make this test pass.
Here's what I've tried so far.
I will try to increase coverage on easier parts.
If you can point me to some direction I will give it another shot, otherwise I can leave that part.
So far I've achieved a 90% coverage!
https://gist.github.com/sebdesign/b2ea5b9dc1bedb3f9614fa8f44031ab8
from byte-stream.
@sebdesign The issue is your output buffer implementation, it needs to be something like this:
<?php
namespace Amp\ByteStream;
use Amp\ByteStream\ClosedException;
use Amp\Deferred;
use Amp\Promise;
use Amp\Success;
class OutputBuffer implements OutputStream, Promise {
private $deferred;
private $contents;
private $closed = false;
public function __construct() {
$this->deferred = new Deferred;
}
public function write(string $data): Promise {
if ($this->closed) {
throw new ClosedException("The stream has already been closed.");
}
$this->contents .= $data;
return new Success(\strlen($data));
}
public function end(string $finalData = ""): Promise {
if ($this->closed) {
throw new ClosedException("The stream has already been closed.");
}
$this->contents .= $finalData;
$this->closed = true;
$this->deferred->resolve($this->contents);
$this->contents = "";
return new Success(\strlen($finalData));
}
public function onResolve(callable $onResolve) {
$this->deferred->promise()->onResolve($onResolve);
}
}
It needs to collect the contents and resolve the promise (async placeholder) once the stream is complete.
from byte-stream.
Thanks for your feedback!
But I'm still getting the same failure when comparing the compressed/uncompressed files.
from byte-stream.
Sorry, didn't have a closer look. The issue is that the stream is written in single byte chunks, so there are other compression blocks generated as when generating the complete file in one chunk. I guess it's best to test the input stream and then test the output stream by writing the output and then reading the contents again and see whether it's the same content (uncompressed).
from byte-stream.
Oh now I get it. That means we won't do any assertions against the compressed file?
from byte-stream.
That's probably best. Another option is to compress the full file in one chunk with the same compression level as the pre-generated file.
from byte-stream.
I got it passing by writing a $fileStream = new ResourceInputStream(fopen($file1, 'r'));
to the OutputBuffer
through the ZlibOutputStream
.
Then I used an InMemoryStream
with the contents of the OutputBuffer
through the ZlibInputStream
to decompress the data and assert against the uncompressed file.
from byte-stream.
I changed the code in the end
method of the ZlibOutputStream
to call the end
method on the destination
.
Then in the test I'm calling yield $gzStream->end()
otherwise nothing works.
One thing I noticed is that the close()
method on the ZlipOutputStream
is not being called.
from byte-stream.
Indeed, the if ($error)
looks wrong in the onResolve
call.
from byte-stream.
We're at 94% now, think I can close this issue.
from byte-stream.
Related Issues (20)
- Low bandwidth v2.0.0-beta.13, v2.0.0-beta.14 HOT 10
- Consider avoiding stream_socket_shutdown HOT 3
- feof may hang HOT 16
- As soon as ResourceInputStream detects EOF, it ignores subsequent requests to read the resource HOT 15
- Broken symlink in docs HOT 2
- Immediate reads and writes might result in blocking HOT 2
- Modify chunk size on the fly HOT 5
- ResourceOutputStream interrupts writing without consumer giving information what was written/unwritten HOT 11
- Problem writing to stream HOT 6
- InputStreamChain HOT 3
- ResourceOutputStream treats open stream as closed HOT 5
- Can cause infinite loop in caller code HOT 2
- Invalid watcher issue in ResourceInputStream
- LineReader custom delimiter HOT 2
- Ability to read particular length from stream HOT 4
- Assertion fail: Trying to read from a previously fclose()'d resource (Windows) HOT 3
- Add InputStream::close
- Add CancellationToken to InputStream::read
- The url inside the composer.json should be in their secure version? HOT 2
- ReadableResourceStream::read() length should reattempt a read if less data is returned? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from byte-stream.