您好,登錄后才能下訂單哦!
這篇文章主要介紹“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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。