Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(MemoryStorage): handling of readable streams for key-value stores…
… when setting records (#1852) Fixes an internally reported bug that caused streams provided to never be read and drained This also corrects the validator for the value, and removes the other redundant checks that happen when validating an object (called constraints, which are extra validators on top of simple typeof checks) (this is also a feature request for shapeshift!). This might actually (finally) solve #1843 but testing needs to be done
- Loading branch information
1 parent
6ad6840
commit a5ee37d
Showing
3 changed files
with
36 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/memory-storage/test/key-value-store-stream.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { MemoryStorage } from '@crawlee/memory-storage'; | ||
import { Readable } from 'node:stream'; | ||
|
||
describe('KeyValueStore should drain streams when setting records', () => { | ||
const storage = new MemoryStorage({ | ||
persistStorage: false, | ||
}); | ||
|
||
const fsStream = Readable.from([Buffer.from('hello'), Buffer.from('world')]); | ||
|
||
test('should drain stream', async () => { | ||
const defaultStoreInfo = await storage.keyValueStores().getOrCreate('default'); | ||
const defaultStore = storage.keyValueStore(defaultStoreInfo.id); | ||
|
||
await defaultStore.setRecord({ key: 'streamz', value: fsStream, contentType: 'text/plain' }); | ||
|
||
expect(fsStream.destroyed).toBeTruthy(); | ||
|
||
const record = await defaultStore.getRecord('streamz'); | ||
expect(record!.value.toString('utf8')).toEqual('helloworld'); | ||
}); | ||
}); |