溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

s3cmd put操作怎么實(shí)現(xiàn)

發(fā)布時(shí)間:2021-12-30 16:20:34 來(lái)源:億速云 閱讀:211 作者:iii 欄目:云計(jì)算

這篇文章主要介紹“s3cmd put操作怎么實(shí)現(xiàn)”,在日常操作中,相信很多人在s3cmd put操作怎么實(shí)現(xiàn)問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”s3cmd put操作怎么實(shí)現(xiàn)”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

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操作的實(shí)現(xiàn)


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官文中對(duì)open函數(shù)的說(shuō)明
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.");

結(jié)論:s3并不支持稀疏文件的儲(chǔ)存,實(shí)際儲(chǔ)存的還是真實(shí)磁盤(pán)容量。進(jìn)行put操作的時(shí)候還是調(diào)用os的file.open()

到此,關(guān)于“s3cmd put操作怎么實(shí)現(xiàn)”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI