流与原始字节 [英] Stream vs Raw Bytes

查看:43
本文介绍了流与原始字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人能帮我弄清楚每种传递文件的方法的优缺点.

I'm hoping someone can help me figure out what the pros and cons are of each method for passing files around.

工作流程类似于:

  1. 将文件保存到数据库
  2. 从数据库中读取文件
  3. 在网页上显示文件

文件是主要图像,但可能有一些视频.在这种情况下我应该使用原始字节还是使用流对象?

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.

这篇关于流与原始字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆