s3cmd put操作怎么实现
发表于:2025-01-27 作者:千家信息网编辑
千家信息网最后更新 2025年01月27日,这篇文章主要介绍"s3cmd put操作怎么实现",在日常操作中,相信很多人在s3cmd put操作怎么实现问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"s3cmd p
千家信息网最后更新 2025年01月27日s3cmd put操作怎么实现
这篇文章主要介绍"s3cmd put操作怎么实现",在日常操作中,相信很多人在s3cmd put操作怎么实现问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"s3cmd put操作怎么实现"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
root:/tmp# dd if=/dev/zero of=sparse-file bs=1 count=1 seek=1024k1+0 records in1+0 records out1 byte (1 B) copied, 0.000509378 s, 2.0 kB/sroot:/tmp# du -sh sparse-file4.0K sparse-file #注意文件大小root:/tmp# md5sum sparse-file9587b149ff392ca6887a05d921e73e72 sparse-fileroot:/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 doneroot:/tmp# s3cmd info s3://us-bucket1/sparse-files3://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:1450427260root:/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 doneroot:/tmp/hwcheck# du -sh sparse-file1.1M sparse-file #注意文件大小md5sum sparse-file9587b149ff392ca6887a05d921e73e72 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.stdinsize = 0else: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操作怎么实现"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
文件
学习
大小
更多
还是
帮助
实用
稀疏
接下来
函数
实际
容量
文章
方法
时候
源码
理论
知识
磁盘
篇文章
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
三星电子软件开发笔试题
攻防演练网络安全检查
网络安全对策6000字
东营瓷砖库存软件开发
软件开发合同 备案 天津
无锡智能化软件开发服务保障
宁畅服务器介绍
普通服务器存储监控视频
《网络安全法》简报
数据库系统安全规范
澳门农副配送软件开发
工业化软件开发公司
盐田服务器系统运维
软件开发测试需要什么设备
网络安全访问控制的三种模式
信号通路研究数据库
江苏省交通互联网科技公司
绩效考核网络安全
长宁区网络技术价格表格
网信筑牢网络安全防线
黑客服务器分析工具
工作生活中网络安全培隐患
六年级网络技术教案
甘肃首选dns服务器云空间
陕西安防时钟监控网管服务器
网络安全公司国企
天水教育网络安全培训
学校网络安全工作实施方案
钱站软件开发商是谁
上半年网络安全工作情况报告