使用 fs 模块创建可读流:
var http = require('http');
var fs = require('fs');
var server = http.createServer(function (req, res) {
var stream = fs.createReadStream(__dirname + '/data.txt');
stream.pipe(res);
});
server.listen(8000);
Run Code Online (Sandbox Code Playgroud)
并通过流模块实例化它:
var Readable = require('stream').Readable;
var rs = new Readable;
rs.push('file.txt');
rs.push('boop\n');
rs.push(null);
rs.pipe(process.stdout);
Run Code Online (Sandbox Code Playgroud) 我无法在 Chrome 52.0 中使用此 CORS 解决方法。我的 iframe 和父页面位于不同的子域上。
我的 iframe 的事件监听器:
window.onload = function () {
window.addEventListener("message", function(event) {
//doesn't log it
console.log('message');
if(event.data === "invokeChildFunction()") {
childFunction();
}
});
function childFunction() {
alert('Parent frame just invoked my function')
}
}
Run Code Online (Sandbox Code Playgroud)
父框架:
var iframeWindow = $('iframe').contentWindow;
var invokeChildFunction = function () {
iframeWindow.postMessage("invokeChildFunction()", "https://mansion-assessment-sdimoff.c9users.io/CORS/index.html");
}
Run Code Online (Sandbox Code Playgroud)
invokeChildFunction()不在 iframe 页面记录任何内容
我试图围绕git冲突,为什么合并这两个会导致冲突?
分支上的file.txt master:
This is line number one
Run Code Online (Sandbox Code Playgroud)
分支上的file.txt feature:
This is line number one
This is line number two
Run Code Online (Sandbox Code Playgroud) 我很难理解代码的第一部分.我不明白我们追求的combine功能.还有什么办法thisOneCounts?真的,我没有评论的任何事我都不明白.
//count the ancestors over 70
function countAncestors(person, test) {
//supposed to combine parents recursively
function combine(person, fromMother, fromFather) {
//stores people over 70
var thisOneCounts = test(person);
//if the person passed the `test` (>70), then 1 is included
return fromMother + fromFather + (thisOneCounts ? 1 : 0);
}
return reduceAncestors(person, combine, 0);
}
//find the percentage of known ancestors, who lived > 70 years
function longLivingPercentage(person) {
var all = countAncestors(person, function(person) {
return …Run Code Online (Sandbox Code Playgroud) 我想添加tres4数组中所有字符串的相应索引,如果它们匹配输入字符串的结尾.然而,我的列表中填充了所有索引1-12,而不是仅匹配输入字符串末尾的那些索引.在这种情况下,只1应该添加到我的List.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Encoding
{
class Program
{
static void Main(string[] args)
{
string[] tres4 = {
"CHU",
"TEL",
"OFT",
"IVA",
"EMY",
"VNB",
"POQ",
"ERI",
"CAD",
"K-A",
"IIA",
"YLO",
"PLA"
};
string message = "CHUTEL";
List<int> digits = new List<int>();
for (int i = 0; i < tres4.Length; i++)
{
if (message.EndsWith(tres4[i]));
{
digits.Add(i);
}
}
Console.WriteLine(String.Join(", ", digits));
}
}
}
Run Code Online (Sandbox Code Playgroud) javascript ×2
.net ×1
c# ×1
cors ×1
git ×1
iframe ×1
node.js ×1
postmessage ×1
recursion ×1
stream ×1