Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Buffer.alloc with non-buffer fill

オープン
#278 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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 はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

feross/buffer のほかの issue

feross/buffer の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。