-
Notifications
You must be signed in to change notification settings - Fork 10
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
FileBox.fromStream() should only be used once, and it must throw if be used again. #50
Comments
Solution 1We can add a flag to Stream type FileBox when doing operations, like |
I believe that this is the expected behavior of the node stream design. Why do we need to use a stream twice, and could we save it to reuse next time so that we can just let the stream passed by? |
I agree this is the expected behavior of the node stream, but this should not be the expected behavior for I believe that the design for |
Yes, you are right, the file box behavior should be consist. The best solution I could think right now, is that all the typed of the file box can be only used once. If the file box has been used once, the next time it should throw an error. The reason for doing this, is that we have to save the stream to memory (or tmp file) if we want to support reusing of the file box. Just image that we have a stream with 1TB data to transfer from the network (e.g. gRPC), and the file box use fromStream and then use toFile to save it. It is obviously we can not call the toFile twice because all the data were gone. |
I agree that if we transfer large data with FileBox, problem will be introduced with multiple operations. But for the current use case, If we change the behavior here, the update will definitely break the current code of the developers using |
I think the streaming type file-box will behave differently from the other types. We might not be able to reuse a stream file box because of the following thoughts:
So for now, the solution that I can imagine is to:
But the above workaround will cause non-consists behavior for the FileBox system, so I'd like to always choose an "always can be able to use once" straitegy for the FileBox. The above is just my draft after start thinking about this problem, please feel free to let me know if you have a better solution, thanks. |
Yes, you are right, seems like it is pretty hard to support reusable Stream FileBox. We should at least throw an exception when the |
I'm glad that you agree with me, and the exception has already added by the last commit yesterday, please upgrade to the latest version of the file box to test it. |
One more thing: do you think we should always throw error when the file box has been used twice, no matter than what type it is? Because as you said, the box might be any type, and the user should get a consist behavior for it. |
Seems like this is a workaround. What do you think about this design below: We add another method into |
I believe the user who is using the FileBox instance should take the responsibility to remember whether this instance has been consumed, and they should not consume the FileBox again because the FileBox has already finished its mission. If anyone wants to get a reusable filehandle, they should save the FileBox to a local temp file so that it can be reused later. |
haha, I just encounter this problem: UnhandledPromiseRejectionWarning: Error: The stream has already been consumed once, and now it was destroyed. See: #50 |
Yy |
Seems like the FileBox in Stream type does not behave the same as all the other types, since the data for this type of FileBox is lazy loaded and can only be transferred once. So how might we support multiple operations on the Stream FileBox?
I created a unit test to test this case and currently it is failed. Let's make it pass.
The text was updated successfully, but these errors were encountered: