Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ariel #2

Open
ghost opened this issue Sep 6, 2018 · 2 comments
Open

Ariel #2

ghost opened this issue Sep 6, 2018 · 2 comments

Comments

@ghost
Copy link

ghost commented Sep 6, 2018

Hi Sergey, i like your book!

I'm having troubbles using the ReadableResourceStream with the async Filesystem utilities:

$filesystem = Filesystem::create($loop);

$file = $filesystem->file($file_path);

$file->open('r')
->then(function($fstream) use($loop, $utilities){
$fstream->on('data', function($chunk) use($utilities){
$stream = new ReadableResourceStream($chunk, $loop);

	return new Response(200, [
		'Content-Type' => 'video/mp4'
	], $stream);
});

$fstream->on('end', function($data) use($fstream){
	$fstream->close();
});

})
->otherwise(function($reason){
if(!$fileStream){
return new Response(404, [
'Content-Type' => 'text/plain'
], "The video doesn't exist on the server.");
}
});

I also have tried passing the $fstream to the ReadableResourceStream and i couldn't been able to return the video stream.
Do you know what its the error?
Thanks in advance!

@seregazhuk
Copy link
Owner

Hi, @arieler Thank you! Could you format your code, please? it's really hard to read and understand your snippet 😞

@ghost
Copy link
Author

ghost commented Sep 10, 2018

Hi @seregazhuk i don't know what happened. Here is the code:

$filesystem = Filesystem::create($loop);

$file = $filesystem->file($file_path);

$file->open('r')
->then(function($fstream) use($loop, $utilities){
	$fstream->on('data', function($chunk) use($utilities){
		$stream = new ReadableResourceStream($chunk, $loop);
		
		return new Response(200, [
			'Content-Type' => 'video/mp4'
		], $stream);
	});
	
	$fstream->on('end', function($data) use($fstream){
		$fstream->close();
	});
})
->otherwise(function($reason){
	if(!$fileStream){
		return new Response(404, [
			'Content-Type' => 'text/plain'
		], "The video doesn't exist on the server.");
	}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant