流与原始字节

编程入门 行业动态 更新时间:2024-10-27 06:25:12
本文介绍了流与原始字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

工作流程类似于:

  • 将文件保存到数据库
  • 从数据库中读取文件
  • 在网页上显示文件
  • 文件是主要图像,但可能有一些视频.在这种情况下我应该使用原始字节还是使用流对象?

    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.

    更多推荐

    流与原始字节

    本文发布于:2023-10-24 09:22:19,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1523563.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:字节   原始

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!