R : readBin and writeBin ( for storing/retrieving MySQL BLOBs or LONGBLOBs )

标签 r binary blob

我正在使用 readBin 函数将文件另存为 MySQL BLOB,如本文所述 ( http://www.r-bloggers.com/save-r-plot-as-a-blob/ )

plot_binary <- paste(readBin("temp.png", what="raw", n=1e6), collapse="")

我的问题是: 一旦它进入数据库,我如何将其转储回文件中?

> f = file ( "backIntoFile.png", "wb")
> writeBin(object = plot_binary, con = f ) 
> close(f)

这不起作用;该文件似乎不是有效的 png ;

干杯!

最佳答案

最好不要使用“粘贴”,因为它将原始数据向量更改为无法作为二进制文件写回的字符串。尝试一下

plot_binary <- readBin("temp.png", what="raw", n=1e6)

> f = file ( "backIntoFile.png", "wb")
> writeBin(object = plot_binary, con = f ) 
> close(f)

我回答你的问题了吗?

关于R : readBin and writeBin ( for storing/retrieving MySQL BLOBs or LONGBLOBs ) ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11606858/

相关文章:

r - 从url下载.file而不使用R指定文件名

R用ggmap对象叠加geom_polygon,空间文件转换

r - 使用 dplyr 按分组年份进行总结

c - 将浮点二进制转换为十进制时,结果略有不准确

c - 在Linux C程序中写入自己的可执行文件,错误 "Text file busy"

sql-server - BLOB 如何存储在索引 View 中?

r - 使用ggplot2找不到对象错误

node.js - 如何删除Azure NodeJS的blob存储容器

javascript - 使用 SAS token 从浏览器访问/更新 Azure Blob 存储是否安全?

algorithm - 为什么二进制搜索索引以这种方式计算?