Buffer.alloc with non-buffer fill
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- javascript, nodejs
- 領域
- web-dev
調査の方向性
まず、Buffer.alloc(size[, fill[, encoding]]) を Node の現在の buffer 実装およびテストと比較します。特に、ここで示されている Uint8Array の fill のケースを確認してください。#177 の関連する議論を確認し、どの Node buffer テストが関係するかを判断します。Uint8Array の 0 から 255 までのバイトが保持され、その動作がテストでカバーされていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Hi @feross!
If you pass a <Uint8Array> as the fill to Buffer.alloc(size[, fill[, encoding]]) node (v14.15.1) will copy those bytes verbatim into the buffer, whereas with the ferros/buffer package, it does something and the end result is that the resulting buffer is filled with strange data.
const input = [ 247, 108, 225 ]
const typedArr = new Uint8Array(input)
const output = Array.from(Buffer.alloc(typedArr.byteLength, typedArr))
// node:
// [ 247, 108, 225 ] (matches input, expected)
// feross/buffer:
// [ 239, 191, 189 ] (???)
It works fine for numbers between 0 and 127, but things get weird once you're out of those bounds (Uint8 should work for numbers between 0 - 255).
Workaround is to pass a Buffer as the fill value:
const output = Array.from(Buffer.alloc(typedArr.byteLength, Buffer.from(typedArr)))
// node:
// [ 247, 108, 225 ] (cool)
// feross/buffer:
// [ 247, 108, 225 ] (cool)
I'd perhaps PR a fix for this specific issue, but I feel like the real problem is that this package needs to be refreshed with the latest buffer code + tests from node, rather than me patching in a specific fix? i.e. Perhaps related to #177. I looked into this briefly and the transform from node looked non-trivial if you haven't done it before.
- 主要言語
- JavaScript
- スター
- 1.9k
- フォーク
- 260
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
feross/buffer のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 48/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 38/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
TheOdinProject/curriculum#31423 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
WGBH-MLA/dream-aapb#69 ·
-
難易度 1/5 1〜3時間 初心者へのやさしさ 78/100
Mintplex-Labs/anything-llm#6490 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
openlayers/ol-cesium#1364 ·