473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

help: loading binary image data into memory


Hi there!
Tried successfully downloading data into memory from internet using the
urllib module like this:
....
import urllib
import cStringIO

url_file = urllib.urlopen(url)
img = cStringIO.StringIO(url_file.read())
....
Was wondering HOW could I accomplish the same results using the ftplib
module
-> retrbinary( command, callback[, maxblocksize[, rest]])
WITHOUT saving any information to the disk;

Will appreciate your comments,
TIA+BRGDS
Jul 18 '05 #1
4 2527
probably something like this: (untested)
def make_ftplib_callback(f):
def callback(block): f.write(block)
return callback
img = cStringIO.StringIO()
retrbinary( "get ???", make_ftplib_callback(img))

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFCWyRhJd01MZaTXX0RArwRAJ9cQqRWBGJB4y9HCSxcWj waJ9cxkgCfZhoI
QDOoVf7HFQwlMIDWasoEPYM=
=xXl5
-----END PGP SIGNATURE-----

Jul 18 '05 #2
Jeff Epler wrote:
probably something like this: (untested)
def make_ftplib_callback(f):
def callback(block): f.write(block)
return callback
img = cStringIO.StringIO()
retrbinary( "get ???", make_ftplib_callback(img))


Ummm, how about

img = cStringIO.StringIO()
retrbinary("get ???", img.write)

?

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Jul 18 '05 #3
Robert Kern wrote:
probably something like this: (untested)
def make_ftplib_callback(f):
def callback(block): f.write(block)
return callback
img = cStringIO.StringIO()
retrbinary( "get ???", make_ftplib_callback(img))


Ummm, how about

img = cStringIO.StringIO()
retrbinary("get ???", img.write)


if you want some additional code to run during download, you can
always do something like:

img = cStringIO.StringIO()
def callback(block):
sys.stdout.write(".")
img.write(block)
if img.tell() > LIMIT:
raise IOError("too much data")
retrbinary(..., callback())

(you don't really have to create a factory if all you need is a single
function...)

you can also get rid of the cStringIO module :

img = []
retrbinary(..., img.append)
# img is now a list of string chunks

might be more efficient, depending on what you plan to do with the
data once you've loaded it.

and finally,

img = urllib.urlopen("ftp://...").read()

might also work.

</F>

Jul 18 '05 #4

tx vm guys, helped a lot

"rixdelei" <ri******@hotmail.com> escribió en el mensaje
news:d3***********@news.wplus.net...

Hi there!
Tried successfully downloading data into memory from internet using the
urllib module like this:
...
import urllib
import cStringIO

url_file = urllib.urlopen(url)
img = cStringIO.StringIO(url_file.read())
...
Was wondering HOW could I accomplish the same results using the ftplib
module
-> retrbinary( command, callback[, maxblocksize[, rest]])
WITHOUT saving any information to the disk;

Will appreciate your comments,
TIA+BRGDS

Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: OneSolution | last post by:
Hi All, Here's what I'm trying to do. I have a diverse customer base, and as it grows, it's increasingly harder to figure out what aspect of our web site is selling and what is not. So I've...
5
by: john | last post by:
Here is the short story of what i'm trying to do. I have a 4 sided case labeling printer setting out on one of our production lines. Now then i have a vb.net application that sends data to this...
3
by: woth | last post by:
Hello guys, I hope you can help me. I have the following line in my code: this.Butterfly = new Bitmap("c:\\butterfly.jpg"); which is pretty simple. The problem is that the size of...
3
by: Josema | last post by:
Hi to all, I have stored in a database some binary files (pdfs, and gif images), i would like to know how could i show it, in internet explorer when a person enters for instance in a textbox the...
3
by: Howler | last post by:
Hello all, I am having a hard time seeing what I am doing wrong with a program I am having to write that converts pbm monochrome images into a similar pgm file. The problem I am having is...
53
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
10
by: eholz1 | last post by:
Hello Members, I am setting up a photo website. I have decided to use PHP and MySQL. I can load jpeg files into the table (medium blob, or even longtext) and get the image(s) to display without...
5
by: weidongtom | last post by:
Hi, I tried to implement the Universal Machine as described in http://www.boundvariable.org/task.shtml, and I managed to get one implemented (After looking at what other's have done.) But when I...
3
by: Stephen Torri | last post by:
Below is a class that is suppose to represent a segment of memory or a contents of a binary image (e.g. ELF executable). I have started to read Modern C++ Design and thought the best way to ensure...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.