我正在尝试编写程序从s3获取zip文件,解压缩,然后将其上传到S3.但我发现了两个我无法捕捉到的例外情况.
1. StreamContentLengthMismatch: Stream content length mismatch. Received 980323883 of 5770104761 bytes.这种不规则发生.
2. NoSuchKey: The specified key does not exist.当我输入错误的密钥时会发生这种情况.
当发生这两个异常时,该程序崩溃.
我想正确地抓住并处理这两个例外.
我想防止崩溃.
const unzipUpload = () => {
return new Promise((resolve, reject) => {
let rStream = s3.getObject({Bucket: 'bucket', Key: 'hoge/hoge.zip'})
.createReadStream()
.pipe(unzip.Parse())
.on('entry', function (entry) {
if(entry.path.match(/__MACOSX/) == null){
// pause
if(currentFileCount - uploadedFileCount > 10) rStream.pause()
currentFileCount += 1
var fileName = entry.path;
let up = entry.pipe(uploadFromStream(s3,fileName))
up.on('uploaded', e => {
uploadedFileCount += 1
console.log(currentFileCount, …Run Code Online (Sandbox Code Playgroud) 我花了整整一天时间,谷歌搜索和寻找答案,但仍然无法弄清楚.
我的代码有点长,它在Firefox中运行良好,但从Chrome中获取"Uncaught SyntaxError:Unexpected token u".
任何人都可以指出我错在哪里吗?提前致谢!
// when the page loads, list all the current contacts
$(document).ready(function(){
// check if localStorage database exists
if(!localStorage.getItem("customerDatabase")){
// define a JSON object to hold all current address
var contacts = {
"users":[
{
"id":"1",
"name":"dennis",
"email":"dennisboys@gmail.com"
},
{
"id":"2",
"name":"zoe",
"email":"zoeisfemale@gmail.com"
}
]
} // end of contacts JSON object
// stringify the object
var stringObject = JSON.stringify(contacts);
// store it into localStorage database
var storedDatabase = localStorage.setItem("customerDatabase", stringObject);
} else {
// …Run Code Online (Sandbox Code Playgroud) 使用switch语句检查变量是否大于某个数字的最佳方法是什么?或者你建议使用if-else?我找到了这样一个例子:
int i;
if(var1>var2) i = 1;
if(var1=var2 i = 0;
if(var1<var2) i = -1;
switch (i);
{
case -1:
do stuff;
break;
case 0:
do stuff;
break;
case 1:
do stuff;
break;
}
Run Code Online (Sandbox Code Playgroud)
你有什么能告诉新手在switch语句中使用"大于或等于"?
当我点击按钮时,我正试图在页面上执行javascript popup.html.我试着用这样的方式:
在background.js中:
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo){
if(changeInfo.status == "loading") {
insert(tabId);
}
});
function insert(tabId) {
chrome.tabs.get(tabId, function(tab) {
$('button').click(function() {
chrome.tabs.executeScript(tab.id, {file: 'js/alert.js'});
});
});
}
Run Code Online (Sandbox Code Playgroud)
Alert.js只包含一个字符串: alert('works');
警报只是一个例子.用户点击im popup.html按钮后,真实脚本应该使用打开的选项卡进行一些DOM操作.
我有两个<div>具有相同背景颜色的s.如何设置背景的宽度?
预期结果:

这是HTML:
<div>
<span>100% width of background</span>
</div>
<div>
<span>75% width of background</span>
</div>
Run Code Online (Sandbox Code Playgroud)
我尝试用CSS做的事情:
div {
background-color: #fc0;
margin: 2px;
}
div:last-child {
background-size: 75%;
}
Run Code Online (Sandbox Code Playgroud)
jsFiddle,当然.
做这个设置width的可行性是否可行div?
在我调查函数时,我意识到我可以创建嵌入式函数.首先,我认为它可能对构造代码很有用.但现在我认为这不是好的编码风格.我对吗?这是一个例子.
function show () {
return function a() {
alert('a');
return function b() {
alert('b');
}
}
}
Run Code Online (Sandbox Code Playgroud)
我可以alert('b')使用这个字符串调用:show()();
在什么情况下最好使用这种方法,什么不是?
我有一个字符串里面有一些西里尔字.每个都以大写字母开头.
var str = '??????????';
Run Code Online (Sandbox Code Playgroud)
我找到了这个解决方案str.match(/[?-?][?-?]+/g).
但它让我感到很["??"]遗憾["????", "??", "????"].似乎它不承认乌克兰字母('і','є'),只有俄语.
那么,我如何更改该正则表达式以包含乌克兰字母?
我正在寻找如何将文本设置为Page Action图标并找到此示例:
window.setInterval(function() {
chrome.pageAction.setIcon({
imageData: draw(10, 0),
tabId: tabId
});
}, 1000);
function draw(starty, startx) {
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var img = new Image();
img.src = "icon_16.png"
img.onload = function() {
context.drawImage(img, 0, 2);
}
//context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(255,0,0,1)";
context.fillRect(startx % 19, starty % 19, 10, 10);
context.fillStyle = "white";
context.font = "11px Arial";
context.fillText("3", 0, 19);
return context.getImageData(0, 0, 19, 19);
}
Run Code Online (Sandbox Code Playgroud)
但是在我把eventPage.js它包括在内之后说Uncaught TypeError: Cannot call method …
如何只将CSS应用于段落中的数字而不包含spans中的数字?
<p>Text and numbers: 123</p>
<p>123 and text</p>
Run Code Online (Sandbox Code Playgroud)
有选择器吗?在jQuery中,也许吧.或者以某种方式使用javascript解析它...
预期结果:

我有两个<span>.首先是font-size: 14px;,我想,以减少font-size孩子<span>的2 px;
<span>14px font <span>12px span</span></span>
Run Code Online (Sandbox Code Playgroud)
如果没有明显的设置怎么做font-size: 12px;?CSS有可能吗?或者我应该使用jQuery?
jsFiddle,当然.