Git Product home page Git Product logo

Comments (9)

 avatar commented on May 27, 2024

没有太明白

from fibjs.

illuspas avatar illuspas commented on May 27, 2024

其实是想使用类似Node中 Buffer.concat()这样的方法合并多个Buffer对象
目前fibjs没这方法
于是我就直接把多个Buffer对象放在数组里面作为参数来new一个Buffer

from fibjs.

jiangzhuo avatar jiangzhuo commented on May 27, 2024

var a = new Buffer([0x01,0x02,0x03]);
var b = new Buffer([0x04,0x05,0x06]);
var c=new Buffer();
c.write(a)
c.write(b)
console.log(c.length)
6
console.log(c.hex());
010203040506

@illuspas
文檔上那個傳Array的構造函數 不是你這個意思。。

from fibjs.

illuspas avatar illuspas commented on May 27, 2024

我的意思是:傳Array的構造函數 能不能就是我這個意思。。

from fibjs.

jiangzhuo avatar jiangzhuo commented on May 27, 2024

那就不是構造函數的問題了
那是需要修改Array的構造函數了,比如說改成:
在兩個參數都是Buffer的情況,把Buffer內的內容按順序拼成一個Array
這顯然不行啊

from fibjs.

illuspas avatar illuspas commented on May 27, 2024

好吧,其实Node里也不能这么构造
要不然就实现 Buffer.concat 这个类方法 以前用node写的程序移植起来就更简单了

from fibjs.

ngot avatar ngot commented on May 27, 2024

@illuspas 我来尝试加 Buffer.concat

from fibjs.

R32 avatar R32 commented on May 27, 2024

我发现 write(Array data)时,只是简单调用了 toString,这样的话这个重载似乎没什么意义,

我感觉 Buffer 的很多地方都不对,相比较nodejs 1)它不应该建立在 std::string 下,它应该是个固定数组,这样的话 write 和 writeXXXX 应该一致,不允许调整尺寸, 2) 移除 resize, 3) 就大数语言的规范,slice 并不会修改原对象,nodejs 也符合,它返回的Buffer是建立在原Buffer上的引用, 修改原对象的应该叫 splice, 还有 slice 的第二个参数 end为负数时,和 str.slice 处理的不一致

from fibjs.

 avatar commented on May 27, 2024

Buffer 的一些实现的确与 nodejs 不兼容,这部分已经安排计划在修改了,多谢关注。

from fibjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.