您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍“s3cmd put操作怎么实现”,在日常操作中,相信很多人在s3cmd put操作怎么实现问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”s3cmd put操作怎么实现”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
root:/tmp# dd if=/dev/zero of=sparse-file bs=1 count=1 seek=1024k 1+0 records in 1+0 records out 1 byte (1 B) copied, 0.000509378 s, 2.0 kB/s root:/tmp# du -sh sparse-file 4.0K sparse-file #注意文件大小 root:/tmp# md5sum sparse-file 9587b149ff392ca6887a05d921e73e72 sparse-file root:/tmp# s3cmd put sparse-file s3://us-bucket1 'sparse-file' -> 's3://us-bucket1/sparse-file' [1 of 1] 1048577 of 1048577 100% in 0s 17.72 MB/s done 'sparse-file' -> 's3://us-bucket1/sparse-file' [1 of 1] 1048577 of 1048577 100% in 0s 5.84 MB/s done root:/tmp# s3cmd info s3://us-bucket1/sparse-file s3://us-bucket1/sparse-file (object): File size: 1048577 #注意文件大小 Last mod: Fri, 18 Dec 2015 08:28:43 GMT MIME type: application/octet-stream MD5 sum: 9587b149ff392ca6887a05d921e73e72 SSE: none policy: none cors: none ACL: en-user1: FULL_CONTROL x-amz-meta-s3cmd-attrs: uid:0/gname:root/uname:root/gid:0/mode:33188/mtime:1450427260/atime:1450427260/md5:9587b149ff392ca6887a05d921e73e72/ctime:1450427260 root:/tmp/hwcheck# s3cmd get s3://us-bucket1/sparse-file 's3://us-bucket1/sparse-file' -> './sparse-file' [1 of 1] 's3://us-bucket1/sparse-file' -> './sparse-file' [1 of 1] 1048577 of 1048577 100% in 0s 23.74 MB/s done root:/tmp/hwcheck# du -sh sparse-file 1.1M sparse-file #注意文件大小 md5sum sparse-file 9587b149ff392ca6887a05d921e73e72 sparse-file
s3cmd put操作的实现 def object_put(self, filename, uri, extra_headers = None, extra_label = ""): # TODO TODO # Make it consistent with stream-oriented object_get() if uri.type != "s3": raise ValueError("Expected URI type 's3', got '%s'" % uri.type) if filename != "-" and not os.path.isfile(deunicodise(filename)): raise InvalidFileError(u"Not a regular file") try: if filename == "-": file = sys.stdin size = 0 else: file = open(deunicodise(filename), "rb") size = os.stat(deunicodise(filename))[ST_SIZE] except (IOError, OSError), e: raise InvalidFileError(u"%s" % e.strerror) python官文中对open函数的说明 open(name[, mode[, buffering]]) Open a file, returning an object of the file type described in section File Objects. If the file cannot be opened, IOError is raised. When opening a file, it’s preferable to use open() instead of invoking the file constructor directly. The first two arguments are the same as for stdio‘s fopen(): name is the file name to be opened, and mode is a string indicating how the file is to be opened. The most commonly-used values of mode are 'r' for reading, 'w' for writing (truncating the file if it already exists), and 'a' for appending (which on some Unix systems means that all writes append to the end of the file regardless of the current seek position). If mode is omitted, it defaults to 'r'. The default is to use text mode, which may convert '\n' characters to a platform-specific representation on writing and back on reading. Thus, when opening a binary file, you should append 'b' to the mode value to open the file in binary mode, which will improve portability. (Appending 'b' is useful even on systems that don’t treat binary and text files differently, where it serves as documentation.) See below for more possible values of mode. The optional buffering argument specifies the file’s desired buffer size: 0 means unbuffered, 1 means line buffered, any other positive value means use a buffer of (approximately) that size (in bytes). A negative buffering means to use the system default, which is usually line buffered for tty devices and fully buffered for other files. If omitted, the system default is used. [2] Modes 'r+', 'w+' and 'a+' open the file for updating (reading and writing); note that 'w+' truncates the file. Append 'b' to the mode to open the file in binary mode, on systems that differentiate between binary and text files; on systems that don’t have this distinction, adding the 'b' has no effect. In addition to the standard fopen() values mode may be 'U' or 'rU'. Python is usually built with universal newlines support; supplying 'U' opens the file as a text file, but lines may be terminated by any of the following: the Unix end-of-line convention '\n', the Macintosh convention '\r', or the Windows convention '\r\n'. All of these external representations are seen as '\n' by the Python program. If Python is built without universal newlines support a mode with 'U' is the same as normal text mode. Note that file objects so opened also have an attribute called newlines which has a value of None (if no newlines have yet been seen), '\n', '\r', '\r\n', or a tuple containing all the newline types seen. Python enforces that the mode, after stripping 'U', begins with 'r', 'w' or 'a'. Python provides many file handling modules including fileinput, os, os.path, tempfile, and shutil. Changed in version 2.5: Restriction on first letter of mode string introduced. 源码中的描述 This module is not normally accessed explicitly by most applications, but can be useful in modules that provide objects with the same name as a built-in value, but in which the built-in of that name is also needed. For example, in a module that wants to implement an :func:`open` function that wraps the built-in :func:`open`, this module can be used directly: import __builtin__ def open(path): f = __builtin__.open(path, 'r') return UpperCaser(f) class UpperCaser: '''Wrapper around a file that converts output to upper-case.''' def __init__(self, f): self._f = f def read(self, count=-1): return self._f.read(count).upper() # ... As an implementation detail, most modules have the name __builtins__ (note the 's') made available as part of their globals. The value of __builtins__ is normally either this module or the value of this modules's :attr:`__dict__` attribute. Since this is an implementation detail, it may not be used by alternate implementations of Python. static PyObject * builtin_open(PyObject *self, PyObject *args, PyObject *kwds) { return PyObject_Call((PyObject*)&PyFile_Type, args, kwds); } PyDoc_STRVAR(open_doc, "open(name[, mode[, buffering]]) -> file object\n\ \n\ Open a file using the file() type, returns a file object. This is the\n\ preferred way to open a file. See file.__doc__ for further information.");
结论:s3并不支持稀疏文件的储存,实际储存的还是真实磁盘容量。进行put操作的时候还是调用os的file.open()
到此,关于“s3cmd put操作怎么实现”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。