开发者

Stream vs Raw Bytes

开发者 https://www.devze.com 2023-01-27 11:40 出处:网络
I\'m hoping someone can help me figure out what the pros and cons ar开发者_如何学JAVAe of each method for passing files around.

I'm hoping someone can help me figure out what the pros and cons ar开发者_如何学JAVAe of each method for passing files around.

The workflow would be something like:

  1. Save the File to DB
  2. Read the file from the DB
  3. Display the file on a webpage

Files are primary images but there maybe some video. Should i be working with the raw bytes in this scenario or use the stream object?

What are the benefits of a stream over raw bytes?


Streams will perform better for large files since not all of it needs to be read into memory at one time (depending on the type of stream of course).

Although there are certainly reasons to store files in a database, generally speaking I would recommend against it. It makes it more difficult to backup your database (larger file means more time to backup and restore), more difficult to view the files outside of your application (can occasionally be very useful, especially when debugging), and can be significantly more expensive since it will take up additional bandwidth, processor, memory, and storage.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号