小编Log*_*gan的帖子

如何使用c ++ boost库获取文件权限?

我正在开发一个项目来创建我当前目录中的文件的数据库.我想要的关于我的文件的一个细节是在ubuntu中使用chmod设置的文件权限.(只是一个注释:我也需要组和所有者信息 - 就像chown-如果你能告诉我,如果提升可以检索所有权信息,那就太棒了.)

我正在使用boost文件系统库,我已多次检查文档,但无法找到如何获取权限.

在此页面中,它显示有enum perms文件权限字符串,这些字符串不会显示在我自己的filesystem.hpp上.(我已经检查过我有1.49版本,也是从源代码构建的,以确保).同样在这里它显示它可以获得如下权限:

perms permissions() const noexcept; 
//Returns: The value of
//permissions() specified by the postconditions of the most recent call
//to a constructor, operator=, or permissions(perms) function.
Run Code Online (Sandbox Code Playgroud)

我无法找到权限函数,也无法找到存储perms列表的位置.

这是我到目前为止的代码(实际上是来自boost教程,但我将其修改为递归),如果你能告诉我如何获得文件权限/所有权或建议另一个库而不是提升我会很感激.

编辑:我已添加s.permissions()为ethan_liou建议,但输出不是预期的.这是更新的代码和输出.

//  filesystem tut4.cpp  ---------------------------------------------------------------//

//  Copyright Beman Dawes 2009

//  Distributed under the Boost Software License, Version 1.0.
//  See http://www.boost.org/LICENSE_1_0.txt

//  Library home page: http://www.boost.org/libs/filesystem

#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <boost/filesystem.hpp>
#include <stdio.h> 
using namespace std; …
Run Code Online (Sandbox Code Playgroud)

c++ ubuntu boost boost-filesystem

5
推荐指数
1
解决办法
9580
查看次数

缓冲函数中的 BE 或 LE 是什么意思?

我有一个 PHP 类,用于读取我正在转换为 NodeJS 的二进制数据或在 NodeJS 中找到等效的几个函数。我对这个 BinaryReader 类感兴趣的函数是ReadULongReadUShort。我相信这些意味着读取无符号长整数(4 个字节)和无符号短整数(2 个字节)。当我试图在 NodeJS 中找到这些的等价物时,我对在这些之间使用哪个函数感到困惑:

buf.readUInt16LE(offset, [noAssert])
buf.readUInt16BE(offset, [noAssert])

buf.readUInt32LE(offset, [noAssert])
buf.readUInt32BE(offset, [noAssert])
Run Code Online (Sandbox Code Playgroud)

在这种情况下会LEBE代表什么?

缓冲的文档都位于这里,但我无法找到工作的人的解释在这里

另外,我在 PHP 类上发现了一个常量,上面写着const DEFAULT_BYTE_ORDER = 'L';. 这是L相同LreadUInt32LE?这是关于字节顺序的全部内容吗?

到目前为止,我已经阅读了这些文章:

如果我能得到更多关于二进制阅读的参考资料,我将不胜感激!

buffer binaryreader node.js

3
推荐指数
1
解决办法
4884
查看次数

如何使用 CSS 制作一个剪裁的半圆(D 形)?

我需要帮助理解剪切路径CSS 属性,以便使我的剪切圆版本如下......

我的圈子

更像设计版本:

设计圈

如果您可以在灰色背景上看到,我的圆圈在被剪裁后显得更大且更圆。

我该怎么做才能使圆圈更圆?我的想法是:

  1. 使用剪辑路径,如下面的代码片段所示
  2. 使用伪:after元素或带半径的右边框
  3. 从 Photoshop 中剪切一个圆形图像并将其用作背景图像。

最好,我想避免使用背景图像。但是,我需要牢记响应能力,因为当我们调整窗口大小时,圆圈无法大幅改变形状。

剪辑路径是正确的方法吗?有人可以用另一种使用 CSS 的方式提出一个更简单、更优雅的解决方案吗?

提前谢谢您,这是我写的一个片段,说明了我如何剪切“绿色/蓝色”背景:

.page-banner {
  background: grey;
  width: 100%;
  height: 300px;
  background-position: top;
  overflow: hidden;
}

.page-banner-text {
  position: absolute;
  background: #00525d8a;
  padding-left: 100px;
  width: 60%;

  /* adjustments to snippet */
  top: 10px;
  left: 10px;
  height: 300px;
  
  /* this is the code for circle */
  clip-path: circle(560px at left);
  padding-right: 250px;
}
Run Code Online (Sandbox Code Playgroud)
<div class="page-banner">
  <div class="container">
    <div class="page-banner-text">
      <h1 class="block-title">Programs For Adults</h1>
      <p>Programs to …
Run Code Online (Sandbox Code Playgroud)

css clip-path

3
推荐指数
1
解决办法
2万
查看次数

如何使用非常规方法从NodeJS中的异步函数传递数据?

我一直在玩jsdom,这是node.js的一个模块.底部的以下代码来自其文档页面.我的问题是如何从异步函数返回一些东西.

我知道这个问题很多,可能也是我的问题.我也知道,当涉及到这类问题时,回调是一个好朋友.我的目标是在PHP中找到一个可能像cookie或Session变量一样的解决方法,以便在异步函数之外将这一小部分数据传输到外部作用域.然后,一旦从外部范围设置数据,就应该可以访问它.

我想知道的第一件事是:

  1. 是否已经有办法将数据存储在外部作用域中存在的cookie或会话中,并且在我完成了必须执行的操作后可以访问?
  2. 如果我要将数据写入文件,在代码中的B点,并在C点读取,那么在读取文件之前,我是否不得不编写某种超时函数等待几秒钟?我在nodejs中使用异步函数的经验有时表明我必须在写入过程完成之前等待几秒钟才能尝试读取它.这也是这种情况吗?如果是的话,这是不是意味着如果我保存数据的地方就是内存呢?
  3. 如果我是为了这个目的而编写一个c ++插件,它就像一个单独的数据托架,我们可以save(data)B点到内存,从Cretrieve(data)点到内存; 这会有用吗?

老实说,我不喜欢编写临时文件来解决异步函数.我一直在寻找一种简单而有效的方法来传递数据,但是我需要像你这样有经验的程序员的一些指导来超越这个问题的不必要的方法.

如果你能为我提出一些想法,说明哪些可行,哪些可能无效,我会很感激.

这是示例代码:

// Print all of the news items on hackernews
var jsdom = require("jsdom");
// var result; 
// A) Outer Scope: Since the function is async in done, storing the result here and echoing in point C is pointless.
jsdom.env({
  html: "http://news.ycombinator.com/",
  scripts: ["http://code.jquery.com/jquery.js"],
  done: function (errors, window) {
    var $ = window.$; …
Run Code Online (Sandbox Code Playgroud)

javascript asynchronous node.js

2
推荐指数
1
解决办法
3953
查看次数

如何使用node.js读取和解析gitconfig文件?

[user]
        name = Alvin J. Alexander
        email = [omitted]
[merge]
        tool = vimdiff
Run Code Online (Sandbox Code Playgroud)

这是~/.gitconfig文件的样子.我以前从未遇到过这样的数据对象.这种格式是否有像json文件这样的名称?或者这是一种自定义格式?

我的目标是从此文件中提取数据以填写package.json模板.我想研究这种格式,以便更好地理解如何解析它.解析函数是否已存在?


以供参考

这是一个解析它的模板:

(需要iniparser安装模块)

var iniparser = require('iniparser');
  var fs = require('fs');
  var home_dir = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
  console.log (home_dir);
  var config_file = home_dir+'/.gitconfig';
  var exists = fs.existsSync(config_file);
  if (exists) {
    console.log("Getting some information from the git configuration...");
    var config = iniparser.parseSync(config_file);
    console.log(config);
    return config;
  }
  else {
    console.log("Git configuration file does not exist...");
    return {};
  };
Run Code Online (Sandbox Code Playgroud)

ini config git-config node.js

2
推荐指数
1
解决办法
3814
查看次数

Neo4j 和 Node js 中的会话过期

我查看了文档:

我使用以下命令创建了一个项目:

npm install --save neo4j-driver
nano index.js
Run Code Online (Sandbox Code Playgroud)

并写下了这段代码:

var neo4j = require('neo4j-driver').v1;

// Create a driver instance, for the user neo4j with password neo4j.
// It should be enough to have a single driver per database per application.
var driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("neo4j", "123456"));

// Register a callback to know if driver creation was successful:
driver.onCompleted = function() {
    // proceed with using the driver, it was successfully instantiated
    console.log('successfully connected');
};

// Register …
Run Code Online (Sandbox Code Playgroud)

neo4j node.js

2
推荐指数
1
解决办法
1320
查看次数

如何将网址/文本中的符号转换为十六进制字符?(转换 = 到 %3D)

使用我正在制作的脚本,jquery 从 url 参数获取变量。它获取的值是一个 url,所以如果它是这样的

http://localhost/index.html?url=http://www.example.com/index.php?something=some

上面写着:

url = http://www.example.com/index.php?something
Run Code Online (Sandbox Code Playgroud)

如果它像

http://localhost/index.html?url=http://www.example.com/index.php?something%3Dsome

上面写着:

url = http://www.example.com/index.php?something%3Dsome

这将注册为有效的网址。我的问题是如何搜索变量=中的符号并将其替换为jquery 或 javascript 的url十六进制?%3D

javascript jquery

1
推荐指数
1
解决办法
4018
查看次数

同步函数调用nodejs mongodb驱动程序

我有一个处理mongodb数据库的开源项目.我正在尝试创建一个查询数据库以检查条目是否存在的函数.

问题是当if_exists()返回true或false时它返回undefined,因为mongodb驱动程序函数是异步的.该文件是Query.js,我在这里尝试了解决问题的方法在Node.js中进行同步MongoDB查询的正确方法是什么?但是我仍然使用get方法得到一个未定义的结果.

使这项工作的最佳方法是什么?

单元测试的输出如下:

running unit tests...
add query test
exists tests:
get: undefined
{}
should be true: undefined
get: undefined
{}
should be false:undefined
Captains Logs listening on port 3000
Captains_Logs v0.5.0-21
[ { name: 'rhcp', _id: 50cbdcbe9c3cf97203000002 } ]
[ { name: 'os', _id: 50cbdcbe9c3cf97203000001 } ]
Run Code Online (Sandbox Code Playgroud)

您可以在WeaponXI/cplog中浏览整个代码

或者快速查看query.js代码是:

var DB = require('../../lib/db.js').DB;

function methods() {
  //query object
  var Q = {};
  //will act as our private variables to workaround …
Run Code Online (Sandbox Code Playgroud)

javascript mongodb node.js node-mongodb-native

1
推荐指数
1
解决办法
9955
查看次数

如何在while循环中调整变量范围以匹配CoffeeScript中的所有正则表达式?

我在coffeescript中使用while循环时遇到了一些麻烦.

原始功能如下,来源是这个答案:

// Return all pattern matches with captured groups
RegExp.prototype.execAll = function(string) {
    var match = null;
    var matches = new Array();
    while (match = this.exec(string)) {
        var matchArray = [];
        for (i in match) {
            if (parseInt(i) == i) {
                matchArray.push(match[i]);
            }
        }
        matches.push(matchArray);
    }
    return matches;
}
Run Code Online (Sandbox Code Playgroud)

它按预期工作.我通过js2coffee转换它,咖啡脚本是:

# Return all pattern matches with captured groups
RegExp::execAll = (string) ->

  matches = new Array()
  match = null
  while match = @exec(string) 
    matchArray = …
Run Code Online (Sandbox Code Playgroud)

javascript regex scope node.js coffeescript

1
推荐指数
1
解决办法
745
查看次数

如何测试上传的文件是否是Node JS中的json文件?

代码

我在我的节点app.coffee文件上有这个咖啡脚本代码来处理上传:

app.post "/import", (req, res) ->
  console.log req.files
  fs.readFile req.files.displayImage.path, (err, data) ->
    newPath = __dirname + "/uploads/" + req.files.displayImage.name
    fs.writeFile newPath, data, (err) ->
      throw err  if err
      res.redirect "/"
Run Code Online (Sandbox Code Playgroud)

在JavaScript转换中,它看起来像这样:

app.post("/import", function(req, res) {
  console.log(req.files);
  return fs.readFile(req.files.displayImage.path, function(err, data) {
    var newPath;
    newPath = __dirname + "/uploads/" + req.files.displayImage.name;
    return fs.writeFile(newPath, data, function(err) {
      if (err) {
        throw err;
      }
      return res.redirect("/");
    });
  });
});
Run Code Online (Sandbox Code Playgroud)

翡翠格式:

  form(action="", method="post", enctype="multipart/form-data")
    input(type="file", name="displayImage")
    input(type="submit", name="Upload")
Run Code Online (Sandbox Code Playgroud)

来自控制台输出的req.files

文件数据如下所示:

{ displayImage: …
Run Code Online (Sandbox Code Playgroud)

javascript json file-upload file-type node.js

0
推荐指数
1
解决办法
3661
查看次数