te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Sharing binary buffer between Node.js server and Browser - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Sharing binary buffer between Node.js server and Browser - Stack Overflow

programmeradmin3浏览0评论

There is an issue of how to share buffers between node.js and the browser containing binary data. I'm pretty happy with Socket.io as a transport layer but the issue is that there is no porting of the Buffer class for the browser. Not something I can find anyways

I've also came across binary.js and I was wondering if there is a good way to bine them having the socket.io as the transport layer and the Binary.js as the data medium. I also saw this question, which is kind of on topic but doesn't really resolve the issue.

I know socket.io added binary support but I haven't found any documentation on the topic.

Update:

It seems that binary.js will not be the solution. The basic requirement that I want is to share the same capabilities that Buffer has in node with the browser.

My needs consist of two things:

  1. Handle the buffer in the same manner in both Server and Browser.

  2. support Binary data.

I will probably use Array Buffer.

Edit: Since node.js run over V8 you can use ArrayBuffer. It seems as if the issue is solved. Yet, from what I know, node people decided that it's a good idea to create a buffer module and manage it in the C bindings they created (from a talk given by Ryan Dahl). I think this has to do with how buffering is done over the network. This means ArrayBuffer is still not a good data medium to share between server and browser.

There is an issue of how to share buffers between node.js and the browser containing binary data. I'm pretty happy with Socket.io as a transport layer but the issue is that there is no porting of the Buffer class for the browser. Not something I can find anyways

I've also came across binary.js and I was wondering if there is a good way to bine them having the socket.io as the transport layer and the Binary.js as the data medium. I also saw this question, which is kind of on topic but doesn't really resolve the issue.

I know socket.io added binary support but I haven't found any documentation on the topic.

Update:

It seems that binary.js will not be the solution. The basic requirement that I want is to share the same capabilities that Buffer has in node with the browser.

My needs consist of two things:

  1. Handle the buffer in the same manner in both Server and Browser.

  2. support Binary data.

I will probably use Array Buffer.

Edit: Since node.js run over V8 you can use ArrayBuffer. It seems as if the issue is solved. Yet, from what I know, node people decided that it's a good idea to create a buffer module and manage it in the C bindings they created (from a talk given by Ryan Dahl). I think this has to do with how buffering is done over the network. This means ArrayBuffer is still not a good data medium to share between server and browser.

Share Improve this question edited May 23, 2017 at 12:16 CommunityBot 11 silver badge asked Sep 1, 2012 at 15:34 qballerqballer 2,1112 gold badges22 silver badges41 bronze badges 7
  • 1 I don't understand what exactly the problem is. What functionality are you exactly interested in that does not exist in the browser? – Benjamin Gruenbaum Commented Sep 1, 2012 at 18:47
  • My needs consist of two things: 1. Handle the buffer in the same manner in both Server and Browser. 2. Support Binary data. – qballer Commented Sep 1, 2012 at 18:53
  • 1 @BenjaminGruenbaum: The problem is not that functionality isn't available in the browser, it's that the functionality that is available in the browser (typed arrays) isn't available in node.js. He doesn't want to have to write all his code twice. – David Schwartz Commented Sep 18, 2012 at 21:56
  • Hi @DavidSchwartz thanks for promoting this question. I've added some details to clarify the Array Buffer issue. – qballer Commented Sep 20, 2012 at 11:19
  • 1 Nope, ArrayBuffer will only e out with IE10. There is still a performance issue with buffering a data structure from the V8. That is why node.js run the buffer module outside of V8 – qballer Commented Sep 20, 2012 at 15:55
 |  Show 2 more ments

2 Answers 2

Reset to default 9 +125

browser-buffer emulates Node's Buffer API in the browser.

It's backed by a Uint8Array, so browser support is sketchy.

JavaScript's built in strings use wide characters internally. So they can easily store a value from 0 to 255 in each character position. This is a JavaScript language feature, so it should work the same in a browser or in node.js.

You can use charCodeAt to extract the value of a particular position in a string and fromCharCode to create a character (that you can add to a string) with a value from 0 to 255.

You can use the various string functions to manipulate data in this form. You can create constants using JavaScript string constants like this "\x00\x12\x34\x56".

发布评论

评论列表(0)

  1. 暂无评论