[web-devel] [Yesod] How to write a field as binary data column.
michael at snoyman.com
Mon Dec 27 21:35:43 CET 2010
2010/12/27 Felipe Almeida Lessa <felipe.lessa at gmail.com>:
> [Please reply to the list as well :-)]
> 2010/12/27 いとうかつとし <cutsea110 at gmail.com>:
>> Umm, This(B.concate . L.toChunks) don't work.
>> an inserted data is incomplete, which is dropped from invisible characters.
>> In my case , the image file with binary data as
>> only "GIF89a^"(7bytes) can be stored.
>> I think I have to escape a binary data.
>> If ByteString field type means binary, I expect the yesod framework to
>> escape automatically.
>> How about?
> That's strange and sounds like a bug. I'm using the same (B.concat .
> L.toChunks) trick and it works very well for me. Are you using
> up-to-date versions of all libraries?
This most certainly *would* be a bug. What backend are you running
this against? Can you create a reproducible test case?
And you didn't ask it directly, but as for the question of why we
don't have direct support for lazy bytestrings: it's because the
database backends don't support it. There is no way with either the
PostgreSQL or Sqlite databases- nor Redis, MySQL or MongoDB- to lazily
send a stream of bytes into the datastore. Giving such a programming
interface would just be a lie: in actuality, Persistent would need to
concatenate all of the lazy chunks into a single strict bytestring.
If you are dealing with relatively small files (relative with regards
to your system available memory), then what you are doing should work
fine. If you are dealing with relatively large files, you should
consider storing the files in the filesystem, and just putting a file
path in the database.
PS: I actually think some of those databases *do* support streaming
BLOBs, but neither persistent nor the underlying libraries have
support for this currently. It could be a nice feature, but since
storing in the filesystem is usually the recommended approach anyway,
adding this is not at the top of my priority list.
> web-devel mailing list
> web-devel at haskell.org
More information about the web-devel