Repository navigation
Doc/processor - #141
Doc/processor#141
Conversation
| $chunk = yield; | ||
| // do something with it | ||
| } while (!$chunk->isLast()); | ||
| ``` |
There was a problem hiding this comment.
We should also explain that the returned value of the processor will be returned by the process method
|
What would be the solution when I want to use it via cli & use e.g. flysystem to save the pdf to another source like a s3 bucket? If I understood the docs correctly, this is right now not possible unless I implement a own |
A StringProcessor would eventually cancel all the memory efficiency that this bundle tries to provide. But yes a custom Processor to leverage https://github.com/async-aws/aws/blob/master/src/Integration/Aws/SimpleS3/src/SimpleS3Client.php#L69 for example to upload chunk by chunk. We are planning for a flysystem native integration with this bundle. |
You're right, you will have to create your own Processor to stream to your bucket. You can use AsyncAws to make it easier. There is no such class in the GotenbergBundle yet but it's planned as a Bridge. |
Here is a naive approach for async aws : https://gist.github.com/Neirda24/05e6a65a862ab34854be3b5f9e562420 As @Jean-Beru said we will try to integrate natively with Flysystem and so on. |
|
and here is a working example for flysystem. https://gist.github.com/Neirda24/f950f1aaa5343c67bcbaeb12ed0cb887 I'll have to investigate more to see if its possible without a tmpfile but I don't see how given the abstraction. |
| }, | ||
| "require-dev": { | ||
| "ext-mbstring": "*", | ||
| "async-aws/s3": "^2.6", |
There was a problem hiding this comment.
might be worth to lower the requirement
| "league/flysystem": "^3.29", | ||
| "league/flysystem-bundle": "^3.3", |
There was a problem hiding this comment.
might be worth to lower the requirement
| "phpstan/phpstan-symfony": "^1.3", | ||
| "phpunit/phpunit": "^10.4", | ||
| "shipmonk/composer-dependency-analyser": "^1.7", | ||
| "shipmonk/composer-dependency-analyser": "^1.8", |
There was a problem hiding this comment.
needed to ignore ext-mbstring issues
What about using kbond filesystem that does all the abstractions for you? |
Not sure hw that would help in this case. Flysystem does not expose a way to write by chunk. the version from kbonc suffers the same issues. |
| public function __invoke(string|null $fileName): \Generator | ||
| { | ||
| if (null === $fileName) { | ||
| $fileName = uniqid('gotenberg_', true); |
There was a problem hiding this comment.
This will be droped soon I think. I don't see a reason filename should be null. I went along with it in this PR but it will change. Otherwise yes filesystem could be a lead.
There was a problem hiding this comment.
yeah because of the getFileName() who's returned $this->response->getFileName(). But I think we can't receive a null or it willcrash with an exception before this part.
| $this->logger?->debug('{processor}: no filename given. Content will be dumped to "{file}".', ['processor' => self::class, 'file' => $fileName]); | ||
| } | ||
|
|
||
| $this->logger?->debug('{processor}: starting multi part upload of "{file}".', ['processor' => self::class, 'file' => $fileName]); |
There was a problem hiding this comment.
private readonly LoggerInterface $logger = new NullLogger()
?
There was a problem hiding this comment.
Why ? This works well already. What kind of gain would we have ?
| $this->filesystemOperator->writeStream($fileName, $tmpfile); | ||
|
|
||
| $this->logger?->debug('{processor}: content dumped to "{file}".', ['processor' => self::class, 'file' => $fileName]); | ||
|
|
||
| return function () use ($fileName) { | ||
| return $this->filesystemOperator->read($fileName); // use readStream instead ? | ||
| }; |
There was a problem hiding this comment.
it does nothing unless you can that callable. I was thinking of returning an anonymous class that implements Stringable and returns this call instead to make it easier to use. What do you suggest ?
| public function __invoke(string|null $fileName): \Generator | ||
| { | ||
| if (null === $fileName) { | ||
| $fileName = uniqid('gotenberg_', true); |
There was a problem hiding this comment.
yeah because of the getFileName() who's returned $this->response->getFileName(). But I think we can't receive a null or it willcrash with an exception before this part.
|
|
||
| ## `Sensiolabs\GotenbergBundle\Bridge\AsyncAws\Processor\AsyncAwsS3MultiPartProcessor` | ||
|
|
||
| Upload using the `async-aws/s3` package. Uploads using the (multipart upload)[https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpuoverview.html] feature of S3. Returns a `AsyncAws\S3\Result\CompleteMultipartUploadOutput` object. |
|
|
||
|
|
||
| <details> | ||
| <summary>If you are not streaming to a browser, you can still process the file using the `process` method instead of `stream`</summary> |
There was a problem hiding this comment.
Back quotes seem to be broken in the preview.
Co-authored-by: Steven Renaux <59167761+StevenRenaux@users.noreply.github.com>
Co-authored-by: Steven Renaux <59167761+StevenRenaux@users.noreply.github.com>
Co-authored-by: Steven Renaux <59167761+StevenRenaux@users.noreply.github.com>
Co-authored-by: Steven Renaux <59167761+StevenRenaux@users.noreply.github.com>
Closes #140